Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function printResult(password) {
- let passwordLength = password.length
- let isValidPassword = true;
- let checkLength = (password) => {
- return passwordLength
- }
- let checkContent = (password) => {
- for (i = 0; i < passwordLength; i++) {
- if (password[i].charCodeAt(0) < 48 || password[i].charCodeAt(0) > 122) {
- return false
- }
- }
- }
- let digitsCount = (password) => {
- let digitCnt = 0;
- for (i = 0; i < passwordLength; i++) {
- if (password[i].charCodeAt(0) >= 48 && password[i].charCodeAt(0) <= 57) {
- digitCnt++
- }
- }
- return digitCnt;
- }
- if (checkLength(password) < 6 && checkLength(password > 10)) {
- console.log("Password must be between 6 and 10 characters")
- isValidPassword = false
- }
- if (checkContent(password) == false) {
- console.log("Password must consist only of letters and digits")
- isValidPassword = false
- }
- if (digitsCount(password) < 2) {
- console.log("Password must have at least 2 digits")
- isValidPassword = false
- }
- if (isValidPassword === true) {
- console.log("Password is valid");
- }
- }
- printResult('MyPass123')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement