javascript - Regular expression with Password -
this question has answer here:
- regular expression password validation 5 answers
var pattern = /^[a-za-z0-9!@#$%^&*()~]+$/; var username = document.getelementbyid("txtusername").value; if(pattern.test(username) == false) { alert("invalid username"); }
the above regex pattern not working. want regular expression password must contain @ least 1 lowercase letter, 1 uppercase letter, 1 digit , 1 special character.
then have make separate tests:
if (/[a-z]/.test(username) && /[a-z]/.test(username) && ...)
you cannot reasonably express requirements in single regex.
Comments
Post a Comment