Skip to main content
 首页 » 编程设计

c#之正则表达式之20 个字符长的数字,只有空格 如何

2024年02月06日30cmt

我对正则表达式完全没用,我需要做的是定义一个模式,该模式将允许最少 5 个字符的字符串,最多 20 个字符将只允许空格和数字,不允许 A-Z。

有什么想法吗?

请您参考如下方法:

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

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