admin管理员组文章数量:1333705
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. I want to change it like this that it takes the combination of number and the character but not only the 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. I want to change it like this that it takes the combination of number and the character but not only the number.
- 1 try this /^[A-Za-z0-9 _]*[A-Za-z]+[A-Za-z0-9 _]*$/ – Aleksandar Gajic Commented Sep 22, 2014 at 9:28
4 Answers
Reset to default 8If 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.
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). A string of only digits will fail.
/^[\w\s]+$/
\w allows letters, numbers and underscores
\s allow spaces
Try this:
^(?![0-9]*$)[a-zA-Z0-9\s_]+$
This expression has a negative lookahead to verify that the string is not only numbers. See it in action with regexr
本文标签:
版权声明:本文标题:javascript - Regular Expression: Allow letters, numbers, and spaces (with at least one letter not number) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739211857a2148859.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论