-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPswdvldtr.js
More file actions
41 lines (35 loc) · 1.12 KB
/
Pswdvldtr.js
File metadata and controls
41 lines (35 loc) · 1.12 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
function pswdvldtr(str) {
let pass = 0;
// Check password length
if (str.length >= 8) {
let hasDigit = false;
let hasUpper = false;
let hasLower = false;
// Iterate through each character in the string
for (let index = 0; index < str.length; index++) {
const element = str[index];
const code = element.charCodeAt(0);
// Check for digit (0-9)
if (48 <= code && code <= 57) {
hasDigit = true;
}
// Check for uppercase letter (A-Z)
else if (65 <= code && code <= 90) {
hasUpper = true;
}
// Check for lowercase letter (a-z)
else if (97 <= code && code <= 122) {
hasLower = true;
}
}
// If all conditions are met, set pass to 1
if (hasDigit && hasUpper && hasLower) {
pass = 1;
}
}
return pass === 1; // Return true if all conditions are met
}
(function main() {
const paswd = "Password123#";
console.log(pswdvldtr(paswd));
})();