Regular Expressions are undoubtedly the first choice for this type of verification problem. However, if regular expressions are not required, they can be written into the verification logic. For this problem, we divide it into two checks: You have to verify a piece of password to confirm that it meets the following conditions:
1. At least 6 characters in length
2. At least one uppercase letter
3. At least one lowercase letter
4. At least one number
5. There are no special characters except 2, 3, and 4, that is, only letters and numbers are contained.
Regular Expressions are undoubtedly the first choice for this type of verification problem. However, if regular expressions are not required, they can be written into the verification logic.
For this problem, we divide it into two checks:
Establish length detection according to the first requirement.
var lengthValid = function(pass){ return pass.length >= 6; };
Based on, a content detection function is created.
The logic is as follows: count the number of uppercase and lowercase letters and numbers in the password string. If a special symbol is encountered, false is returned directly.
var contentValid = function(pass){ var lowerNum = 0; var upperNum = 0; var numNum = 0; for(var i=0;i
= 48 && code <= 57){ numNum++; } else if(code >= 65 && code <= 90){ upperNum++; } else if(code >= 97 && code <= 122){ lowerNum++; } else{ return false; } } return lowerNum && upperNum && numNum; };
Finally, the length Detection and content detection are integrated to form a password verification function:
function validate(password) { return lengthValid(password) && contentValid(password); }
The above is the JavaScript interesting question: password verification content. For more information, please follow the PHP Chinese Network (www.php1.cn )!