Regex password validation in javascript
In this first example, the password must be at least 8 characters long and start and end with a letter.
var re = /^[A-Za-z]\w{6,}[A-Za-z]$/;
if (!re.test(myString)) { alert("Please enter a valid password!"); }
In this second example, the password length doesn't matter, but the password must contain at least 1 number, at least 1 lower case letter, and at least 1 upper case letter.
var re = /^\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*$/
if (!re.test(myString)) { alert("Please enter a valid password!"); }
Password Regular Expression Pattern is as follows:
var re = /^[A-Za-z]\w{6,}[A-Za-z]$/;
if (!re.test(myString)) { alert("Please enter a valid password!"); }
In this second example, the password length doesn't matter, but the password must contain at least 1 number, at least 1 lower case letter, and at least 1 upper case letter.
var re = /^\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*$/
if (!re.test(myString)) { alert("Please enter a valid password!"); }
Password Regular Expression Pattern is as follows:
((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})
Explanation : ( # Start of group
?= – means apply the assertion condition, meaningless by itself, always work with other combination
Tags : regex validation, javascript, regex
Comments
Post a Comment