WEB开发网
开发学院网页设计JavaScript JS检测密码强度 阅读

JS检测密码强度

 2012-10-11 16:09:02 来源:WEB开发网   
核心提示:function _getPasswordStrength(password) { return 0 // if password bigger than 5 give 1 point + +(password.length > 5) // if password
function _getPasswordStrength(password) {
    return 0
        // if password bigger than 5 give 1 point
        + +(password.length > 5)
        // if password has both lower and uppercase characters give 1 point
        + +(/[a-z]/.test(password) && /[A-Z]/.test(password))
        // if password has at least one number and at least 1 other character give 1 point
        + +(/\d/.test(password) && /\D/.test(password))
        // if password has a combination of other characters and special character give 1 point
        + +(/[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/.test(password) && /\w/.test(password))
        // if password bigger than 12 give 1 point
        + +(password.length > 12);
};

console.log(_getPasswordStrength('asdfASDF12 341542$$@#!$'));

Tags:JS 检测 密码

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接