Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function password(arr) {
- function length(arr) {
- return arr.length >= 6 && arr.length <= 10;
- }
- function lettersAndDigits(arr) {
- return !!arr.match("^[A-Za-z0-9]+$");
- }
- function atLeast2Digits(arr) {
- let split = arr.split("");
- let counter = 0;
- for (i = 0; i<split.length;i++) {
- if (split[i]>=0) counter++;
- }
- if (counter>=2) return true;
- }
- if (!length(arr)) {console.log("Password must be between 6 and 10 characters")}
- if (!lettersAndDigits(arr)) {console.log("Password must consist only of letters and digits")}
- if (!atLeast2Digits(arr)) {console.log("Password must have at least 2 digits")}
- if (length(arr) && lettersAndDigits(arr) && atLeast2Digits(arr)) {console.log("Password is valid")}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement