Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function passwordValidation(password) {
- const isValid = (pass) => {
- const isCharInt = /^[A-Za-z0-9]*$/.test(pass);
- const lengthIsValid = pass.length >= 6 && pass.length <= 10;
- const minDigits = pass.replace(/[^0-9]/g, '').length;
- if (isCharInt && lengthIsValid && minDigits >= 2) {
- console.log('Password is valid');
- }
- if (!lengthIsValid) {
- console.log('Password must be between 6 and 10 characters');
- }
- if (!isCharInt) {
- console.log('Password must consist only of letters and digits');
- }
- if (minDigits < 2) {
- console.log('Password must have at least 2 digits');
- }
- };
- return isValid(password);
- }
Add Comment
Please, Sign In to add comment