2015-01-16 16 views
1

我在正則表達式中完全沒用,我需要做的是定義一個模式,該模式允許一個字符串最少5個字符,最多20個字符將允許空格和只有數字,沒有AZ。正則表達式 - 20個字符只與空格的長數字如何

任何想法?

+2

'^ [A-ZA-Z] {5,20} $'應該工作。 – anubhava

+0

'@^[\ sa-zA-Z] {5,20} $' –

+1

字符是指字母還是您需要符號? –

回答

4

您可以使用以下正則表達式:

@"^[\d ]{5,20}$" 

說明:

^    # the beginning of the string 
[\d ]{5,20} # any character of: digits (0-9), ' ' (between 5 and 20 times) 
$    # before an optional \n, and the end of the string 
相關問題