正则表达式不应仅允许数字 [英] Regular Expression should not allow numbers alone
问题描述
我想要正则表达式,可以接受数字和字母或只是字母而不仅仅是数字。
我是这个表达的新手,任何人都建议我表达。
有效:
字母+数字
仅限字母
数字+字母
无效:
0-9(仅限数字)
试试以下正则表达式
^ \d * [a-zA- Z] {1,} \ d *
如果字符串包含至少1个字母和任意数字的数字,则此值有效。
我在上面的正则表达式中尝试使用C#代码我在评论中分享了以下字符串
abc:有效,
abc1:有效,
1abc:有效,
111:无效
a1b1c1:有效
谢谢
Milind
实际上这个/ ^ [0-9] * [a-zA-Z _] + [a-zA-Z0-9 _] *
/
实际上是这个/ ^ [a-zA-Z0-9 _] * [a-zA-Z _] + [a-zA-Z0-9 _] *
I want regular expression that can accept numbers and alphabets or just alphabets but not numbers only.
I am new to this expressions, any one suggest me the expression.
valid:
alphabets + numerics
alphabets only
numerics + alphabets
Invalid:
0-9(numerics only)
Hi,
Try following regex
^\d*[a-zA-Z]{1,}\d*
This will be valid if string has atleast 1 alphabet and any number of digit.
I tried above regex using C# code I shared in the comment for following string
abc : Valid,
abc1: Valid,
1abc: Valid,
111: Invalid
a1b1c1: Valid
Thanks
Milind
actually this /^[0-9]*[a-zA-Z_]+[a-zA-Z0-9_]*
/
actually this /^[a-zA-Z0-9_]*[a-zA-Z_]+[a-zA-Z0-9_]*
这篇关于正则表达式不应仅允许数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!