ad_login/wwwroot/assets/javascript/custom/newFile.js

31 lines
850 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

$(document).ready(function () {
});
/**
* 檢查輸入的密碼強度,先檢查密碼是否達到指定的長度,
* 再檢查是否有達成包含「英文小寫、英文大寫、阿拉伯數字、特殊符號」四個項目,可透過`strength`設定至少要符合多少項。
* https://klab.tw/2023/01/check-password-strength-using-java-and-javascript/
* @param {string} str - 要檢測的密碼文字
* @param {number} length - 需要的密碼長度
* @param {number} strength - 需要符合的項目數量0到4
* @returns 如果符合強度需求返回true
*/
function pwdStrengthChecke(str, length, strength) {
if (!str || str.length < length) {
return false
}
let n = 0
const regex = [
/[a-z]/,
/[A-Z]/,
/[0-9]/,
/[`~!@#$%^&*()_+=,<>\-\[\]\{\}\:;\.'"\/\\?\|]/
]
for (const r of regex) {
if (str.match(r)) {
n++
}
}
return n >= strength
}