[英]Regular Expression For At Least One Number
How would you create a regular expression for a value that should contain at least one number? 如何为应包含至少一个数字的值创建正则表达式? The user can enter any special character, letter etc., but should contain at least one number. 用户可以输入任何特殊字符,字母等,但应至少包含一个数字。
I tried with pattern="[\\w+]{6,20}"
and 我尝试使用pattern="[\\w+]{6,20}"
和
(?=.*\d)(*[a-z])(*[A-Z]).{6,20}
Neither are working. 两者都没有工作。
Try using this pattern 尝试使用此模式
.*[0-9].*
For 6 to 20 use this 6至20使用此
^(?=.*\d).{6,20}$
Use this Regex 使用此正则表达式
An easier solution would be to retain your existing regex, then create two new regexes to test for your "at least one alphabetic" and "at least one numeric". 一个更简单的解决方案是保留现有的正则表达式,然后创建两个新的正则表达式来测试“至少一个字母”和“至少一个数字”。
So, test for this :- 所以,测试一下: -
/^([a-zA-Z0-9]+)$/
Then this :- 然后这个: -
/\d{1}/
Then this :- 然后这个: -
/[A-Z]{1}/i
您可以使用此模式:
/^(?=.{6,20}$)\D*\d/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.