Advertisement
Kamend1

Untitled

Mar 6th, 2025
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve (password) {
  2.     let passArr = password.split('');
  3.     let passValid = true;
  4.  
  5.     if (passArr.length < 6 || passArr.length > 10) {
  6.         console.log("Password must be between 6 and 10 characters");
  7.         passValid = false;
  8.     }
  9.  
  10.     function isAlphanumeric(str) {
  11.         return /^[a-zA-Z0-9]+$/.test(str);
  12.     }
  13.  
  14.     if (!isAlphanumeric(password)) {
  15.         console.log("Password must consist only of letters and digits");
  16.         passValid = false;
  17.     }
  18.  
  19.     function hasTwoDigits(str) {
  20.         return (str.match(/[0-9]/g) || []).length >= 2;
  21.  
  22.     }
  23.  
  24.     if(!hasTwoDigits(password)) {
  25.         console.log("Password must have at least 2 digits");
  26.         passValid = false;
  27.     }
  28.  
  29.     if (passValid) {
  30.         console.log("Password is valid")
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement