Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对验证输入字段有以下要求:
例如,表达式应接受以下字符串"my name is wish"。
"my name is wish"
我正在使用的正则表达式是:
RegExp.Pattern = "^[\a-zA-Z]*[\s]*[\a-zA-Z]*[\s]*[\a-zA-Z]*$"
当我输入名称为“abc abc abc6”时,它认为它是有效的。由于输入了数字,它应该会出错。
试试这个模式
^[a-zA-Z]+(?:\s+[a-zA-Z]+)*$
图案说明:
^ Start of string [a-zA-Z] Any character in the class a to z or A to Z + One or more repititions (?: ) Match expresion but don't capture \s+ Whitespace, One or more repititions * Zero or more repititions $ End of string