-
Notifications
You must be signed in to change notification settings - Fork 546
Expand file tree
/
Copy pathpremdaripa.js
More file actions
47 lines (38 loc) · 1.17 KB
/
premdaripa.js
File metadata and controls
47 lines (38 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function validatePassword(password) {
// Define the regular expressions for various password criteria
const minLength = 8; // Minimum password length
const hasUppercase = /[A-Z]/;
const hasLowercase = /[a-z]/;
const hasDigit = /[0-9]/;
const hasSpecialChar = /[!@#$%^&*()_+{}\[\]:;<>,.?~\\/-]/; // You can customize this list of special characters
// Check the minimum length
if (password.length < minLength) {
return false;
}
// Check for uppercase letters
if (!hasUppercase.test(password)) {
return false;
}
// Check for lowercase letters
if (!hasLowercase.test(password)) {
return false;
}
// Check for at least one digit
if (!hasDigit.test(password)) {
return false;
}
// Check for at least one special character
if (!hasSpecialChar.test(password)) {
return false;
}
// If all criteria are met, the password is valid
return true;
}
// Example usage:
const password = "MyP@ssw0rd";
const isValid = validatePassword(password);
if (isValid) {
console.log("Password is valid.");
} else {
console.log("Password is invalid.");
}