31 lines
643 B
JavaScript
31 lines
643 B
JavaScript
const validatePassword = (password) => {
|
|
// Check if password is a string
|
|
if (typeof password !== "string") {
|
|
return false;
|
|
}
|
|
|
|
// At least 1 uppercase letter
|
|
const hasUppercase = /[A-Z]/.test(password);
|
|
|
|
// At least 1 lowercase letter
|
|
const hasLowercase = /[a-z]/.test(password);
|
|
|
|
// At least 1 symbol
|
|
const hasSymbol = /[^A-Za-z0-9]/.test(password);
|
|
|
|
// At least 4 numbers
|
|
const numberCount = (password.match(/[0-9]/g) || []).length;
|
|
|
|
const hasFourNumbers = numberCount >= 4;
|
|
|
|
return (
|
|
hasUppercase &&
|
|
hasLowercase &&
|
|
hasSymbol &&
|
|
hasFourNumbers
|
|
);
|
|
};
|
|
|
|
module.exports = {
|
|
validatePassword,
|
|
}; |