[英]Regular Expression: Allow letters, numbers, and spaces (with at least one letter not number)
I'm currently using this regex ( /^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$/
) to accept letters, numbers, spaces and underscores. 我正在使用这个正则表达式( /^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$/
)接受字母,数字,空格和下划线。 I want to change it like this that it takes the combination of number and the character but not only the number. 我想改变它,它需要数字和字符的组合,而不仅仅是数字。
If i understand correctly you want to allow a string that begins with at least one letter and optionally is followed by number or underscore or space. 如果我理解正确,您希望允许以至少一个字母开头的字符串,并且可选地后跟数字或下划线或空格。
Try this: /^(?:[A-Za-z]+)(?:[A-Za-z0-9 _]*)$/
at this online regex tester . 试试这个: /^(?:[A-Za-z]+)(?:[A-Za-z0-9 _]*)$/
在这个在线正则表达式测试仪上 。
This should work. 这应该工作。
Cheers! 干杯!
Try this: 尝试这个:
/^[A-Za-z0-9 _]*[A-Za-z]+[A-Za-z0-9 _]*$/
This allows for 0 or more of each of the outside groups, and 1 or more of the inner group (letters only). 这允许每个外部组中的0个或更多个,以及内部组中的一个或多个(仅字母)。 A string of only digits will fail. 只有一串数字才会失败。
/^[\w\s]+$/
\\w allows letters, numbers and underscores \\ w允许字母,数字和下划线
\\s allow spaces \\ s允许空格
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.