Advertisement
Guest User

forNow

a guest
Feb 16th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. function passwordValidator(word) {
  2. let password = word.split('');
  3. let isValid = true;
  4.  
  5. if (password.length >= 6 && password.length <= 10) {
  6. isValid = true;
  7.  
  8. } else {
  9. console.log(`Password must be between 6 and 10 characters`);
  10. }
  11.  
  12. for (let i = 0; i < password.length; i++) {
  13. let current = password[i];
  14. if (password[i] >= String.fromCharCode(65) && password[i] <= String.fromCharCode(90)) {
  15. isValid = true;
  16.  
  17. } else if (password[i] >= String.fromCharCode(97) && password[i] <= String.fromCharCode(122)) {
  18. isValid = true;
  19.  
  20. } else if (password[i] >= String.fromCharCode(48) && password[i] <= String.fromCharCode(57)) {
  21. isValid = true;
  22.  
  23. } else {
  24. isValid = false;
  25. console.log(`Password must consist only of letters and digits`);
  26. break;
  27. }
  28.  
  29.  
  30. }
  31.  
  32.  
  33. }
  34.  
  35.  
  36. passwordValidator('MyPass123')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement