Password Validation
Password validation is the authentication process during the form filling at any website.
It includes various formats, according to which a user must create the password. The different kinds of formats are described below in this blog.
To check a password between 6 to 20 characters which contains at least one numeric digit, one uppercase, and one lowercase letter,
JavaScript code
<script>
function CheckPassword(inputtxt) {
var passw = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,20}$/;
if (inputtxt.value.match(passw)) {
alert('Correct, try another...')
return true;
}
else {
alert('Wrong...!')
return false;
}
}
</script>
To check a password between 7 to 16 characters, which should contain only characters, numeric digits, and underscore, and the first character must be a letter,
JavaScript code
var passw= /^[A-Za-z]\w{7,14}$/;
To check a password between 7 to 15 characters, which should contain at least one numeric digit and a special character,
JavaScript code
var passw= /^(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{7,15}$/;
To check a password between 8 to 15 characters, which should contain at least one lowercase letter, one uppercase letter, one numeric digit, and one special character,
Javascript code
var passw= /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\s).{8,15}$/;
The other type can also be made by applying different logic.