Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function passValidator(password){
- let isLong=passIsLong(password)
- let [isLettersAndNums,numSpotted]=passIsLettersAndDigits(password)
- if(!isLong){
- console.log("Password must be between 6 and 10 characters")
- }
- if(!isLettersAndNums){
- console.log("Password must consist only of letters and digits")
- }
- if(numSpotted<2){
- console.log("Password must have at least 2 digits")
- }
- if(isLong&&isLettersAndNums&&numSpotted>=2){
- console.log("Password is valid")
- }
- function passIsLong(pass){
- let isLong=""
- if(pass.length>=6&&pass.length<=10){
- isLong=true
- }
- else{
- isLong= false
- }
- return isLong
- }
- function passIsLettersAndDigits(pass){
- let passLetters=pass.split("")
- let isLettersAndNums=""
- let numSpotted=0
- for(let letter of passLetters){
- let letterChar=letter.charCodeAt(0)
- if(letterChar>=48&&letterChar<=57||letterChar>=65&&letterChar<=90||letterChar>=97&&letterChar<=122){
- isLettersAndNums=true
- }
- else{
- isLettersAndNums=false
- break;
- }
- }
- for(let num of passLetters){
- let numChar=num.charCodeAt(0)
- if(numChar>=48&&numChar<=57){
- numSpotted++
- }
- }
- return [isLettersAndNums,numSpotted]
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement