正则表达式的字母数字,但至少有一个字符 [英] regex for alphanumeric, but at least one character
本文介绍了正则表达式的字母数字,但至少有一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的asp.net页面上,我有一个输入框,必须具有以下验证就可以了:
必须是字母数字,至少有1个字符(即不能是所有的数字)。
解决方案
^ \ D * [A-ZA-Z] [A-ZA-Z0-9] * $
基本上,这意味着:
- 在零个或多个ASCII数字;
- 一个字母的ASCII字符;
- 在零个或多个字母数字ASCII字符。
尝试了一些测试,你会看到这个会经过其中至少有一个非数字的ASCII字符需要的任何字母数字的ASCII字符串。
这里的关键是 \ D *
在前面。没有它的正则表达式变得更尴尬的事情。
In my asp.net page, I have an input box that has to have the following validation on it:
Must be alphanumeric, with at least 1 character (i.e. can't be ALL numbers).
解决方案
^\d*[a-zA-Z][a-zA-Z0-9]*$
Basically this means:
- Zero or more ASCII digits;
- One alphabetic ASCII character;
- Zero or more alphanumeric ASCII characters.
Try a few tests and you'll see this'll pass any alphanumeric ASCII string where at least one non-numeric ASCII character is required.
The key to this is the \d*
at the front. Without it the regex gets much more awkward to do.
这篇关于正则表达式的字母数字,但至少有一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文