I have a regular expression to validate a password to contain numbers, lowercase and uppercase characters.
The one below works fine. But when I use this in jQuery Validation:
txtPassword: {
required: true,
regex: Regex
}
Regex = (?=^.{8,16}$)(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()_+}{":;/'?/>.<,])(?!.*\s).*$
But the issue is single quote ' in Javascript. Can some body please help me to resolve this? Thankyou.
There are several things that need to fixed in this regex:
a quantifier. Hence it will always fail that check. For e.g., for the
number check, you should have
(?=.*\d)instead of(?=.\d)./, instead youuse a backslash
\. You have it escaped incorrectly with aforwardslash in the last character class.
class are the closing bracket (
]), the backslash (\), the caret (^)and the hyphen (
-). Hence it is not due to the single quote. The culprit is your caret which is not escaped.Try this regex where the caret
^is escaped instead of the quote':I am assuming by your question, you meant a Regexp to validate a password with:
!@#$%^&*()_+}{":;'?/>.<,If this is true, please update your question with the clarified requirement.
Play with the regex in RegexPal
jQuery based code. Fiddle with this here: