didkoslawow

Untitled

Jan 17th, 2023
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. function passwordValidation(password) {
  2. const isValid = (pass) => {
  3. const isCharInt = /^[A-Za-z0-9]*$/.test(pass);
  4. const lengthIsValid = pass.length >= 6 && pass.length <= 10;
  5. const minDigits = pass.replace(/[^0-9]/g, '').length;
  6.  
  7. if (isCharInt && lengthIsValid && minDigits >= 2) {
  8. console.log('Password is valid');
  9. }
  10. if (!lengthIsValid) {
  11. console.log('Password must be between 6 and 10 characters');
  12. }
  13. if (!isCharInt) {
  14. console.log('Password must consist only of letters and digits');
  15. }
  16. if (minDigits < 2) {
  17. console.log('Password must have at least 2 digits');
  18. }
  19. };
  20.  
  21. return isValid(password);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment