Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function passwordValidator(word) {
- let password = word.split('');
- let isValid = true;
- let digits = 0;
- lengthValidator(password)
- function lengthValidator(password) {
- if (password.length >= 6 && password.length <= 10) {
- isValid = true;
- return true;
- } else {
- console.log(`Password must be between 6 and 10 characters`);
- }
- }
- for (let i = 0; i < password.length; i++) {
- let current = password[i];
- if (password[i] >= String.fromCharCode(65) && password[i] <= String.fromCharCode(90)) {
- isValid = true;
- } else if (password[i] >= String.fromCharCode(97) && password[i] <= String.fromCharCode(122)) {
- isValid = true;
- } else if (password[i] >= String.fromCharCode(48) && password[i] <= String.fromCharCode(57)) {
- isValid = true;
- digits++;
- } else {
- isValid = false;
- console.log(`Password must consist only of letters and digits`);
- break;
- }
- }
- if (digits >= 2) {
- isValid = true;
- } else {
- isValid = false;
- console.log(`Password must have at least 2 digits`)
- }
- if (isValid) {
- console.log(`Password is valid`)
- }
- }
- passwordValidator('MyPass123')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement