admin管理员组文章数量:1023794
I'm trying to write a regex for javascript which will allow letters and numbers but won't allow numbers alone.
So '12 Test Street' would validate, as would 'test street' but not '12'.
Not that familiar with regexs so I've no idea where to start. I managed to write:
^([A-Za-z\d\s]+[A-Za-z\s])+$
That does work to a point but if a space is then added to the end of the numbers, it will validate again.
I'm trying to write a regex for javascript which will allow letters and numbers but won't allow numbers alone.
So '12 Test Street' would validate, as would 'test street' but not '12'.
Not that familiar with regexs so I've no idea where to start. I managed to write:
^([A-Za-z\d\s]+[A-Za-z\s])+$
That does work to a point but if a space is then added to the end of the numbers, it will validate again.
Share Improve this question asked Jul 2, 2014 at 16:01 Alex FoxleighAlex Foxleigh 1,9742 gold badges22 silver badges52 bronze badges 02 Answers
Reset to default 8You can solve this easily with a negative look-ahead:
^(?!\d+$)[a-zA-Z\d\s]+$
Note that this allows space-only strings. I'll leave it as a small exercise to change the expression if that's not desired. :)
If I interpret almost strictly (you did not mention whitespace characters) your question I suppose this will work:
^\d*[a-zA-Z][a-zA-Z\d\s]*$
I'm trying to write a regex for javascript which will allow letters and numbers but won't allow numbers alone.
So '12 Test Street' would validate, as would 'test street' but not '12'.
Not that familiar with regexs so I've no idea where to start. I managed to write:
^([A-Za-z\d\s]+[A-Za-z\s])+$
That does work to a point but if a space is then added to the end of the numbers, it will validate again.
I'm trying to write a regex for javascript which will allow letters and numbers but won't allow numbers alone.
So '12 Test Street' would validate, as would 'test street' but not '12'.
Not that familiar with regexs so I've no idea where to start. I managed to write:
^([A-Za-z\d\s]+[A-Za-z\s])+$
That does work to a point but if a space is then added to the end of the numbers, it will validate again.
Share Improve this question asked Jul 2, 2014 at 16:01 Alex FoxleighAlex Foxleigh 1,9742 gold badges22 silver badges52 bronze badges 02 Answers
Reset to default 8You can solve this easily with a negative look-ahead:
^(?!\d+$)[a-zA-Z\d\s]+$
Note that this allows space-only strings. I'll leave it as a small exercise to change the expression if that's not desired. :)
If I interpret almost strictly (you did not mention whitespace characters) your question I suppose this will work:
^\d*[a-zA-Z][a-zA-Z\d\s]*$
本文标签: javascriptRegex to allow letters and numbers but not numbers aloneStack Overflow
版权声明:本文标题:javascript - Regex to allow letters and numbers but not numbers alone - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745605751a2158717.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论