admin管理员组文章数量:1401959
I want to validate a string using jQuery.match() function. String must contain
- Minimum of 10 characters.
- Must contains atleast one numeral.
- Must contain atleast one capital letter.
How can I do that? Can anyone show me the regular expression to do that?
I am already have this:
^(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$
but it is validating like this only, allow atleast one special character, one uppercase, one lowercase(in any order).
I want to validate a string using jQuery.match() function. String must contain
- Minimum of 10 characters.
- Must contains atleast one numeral.
- Must contain atleast one capital letter.
How can I do that? Can anyone show me the regular expression to do that?
I am already have this:
^(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$
but it is validating like this only, allow atleast one special character, one uppercase, one lowercase(in any order).
Share Improve this question edited Sep 19, 2013 at 9:54 Rohit Jain 213k45 gold badges414 silver badges533 bronze badges asked Sep 19, 2013 at 9:54 CoolCool 3482 gold badges11 silver badges32 bronze badges 03 Answers
Reset to default 5It is not strictly conforming to the length restriction, because you haven't done it correctly. The first look-ahead - (?=.{8,})
, is just testing for string with minimum length 8
. Remember, since the look-arounds are 0-length assertions, the look-aheads after .{8,0}
are not consuming any character at all.
In fact, you can remove that first look-ahead, and simply use that quantifier at the end while matching.
Try this regex:
^(?=.*[A-Z])(?=.*[0-9]).{10,}$
Break up:
^
(?=.*[A-Z]) # At least an uppercase alphabet
(?=.*[0-9]) # At least a numeral
.{10,} # Any character 10 or more times
$
I'm not sure how you got that regex; it seems to have been taken somewhere...
^(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$
^^^^ ^^^^^ ^^^^^ ^--------^
1 2 3 4
Makes sure there's at least 8 characters
Makes sure there's lowercase characters
Makes sure there's uppercase characters
Makes sure there are those special characters.
To make a regex to your requirements, do some changes:
^(?=.{10})(?=.*[0-9])(?=.*[A-Z]).*$
^^^^ ^^^^^ ^^^^^
1 2 3
Makes sure there's at least 10 characters
Makes sure there's at least a number.
Makes sure there's at least an uppercase letter.
You can make it a bit shorter using:
^(?=.*[0-9])(?=.*[A-Z]).{10,}$
^ # Start of group
(?=.*\d) # must contain at least one digit
(?=.*[A-Z]) # must contain at least one uppercase character
. # match anything with previous condition checking
{10,} # length at least 10 characters
$ # End of group
i.e.:
^(?=.*\d)(?=.*[A-Z]).{10,}$
Source:
- Password matching expression
本文标签:
版权声明:本文标题:javascript - Regular expression for minimum of 10 characters and include 1 numeral and one capital letter - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744248782a2597150.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论