正则表达式 - 20个字符只与空格的长数字如何

问题描述:

我在正则表达式中完全没用,我需要做的是定义一个模式,该模式允许一个字符串最少5个字符,最多20个字符将允许空格和只有数字,没有AZ。正则表达式 - 20个字符只与空格的长数字如何

任何想法?

+2

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

+0

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

+1

字符是指字母还是您需要符号? –

您可以使用以下正则表达式:

@"^[\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