Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve (password) {
- let passArr = password.split('');
- let passValid = true;
- if (passArr.length < 6 || passArr.length > 10) {
- console.log("Password must be between 6 and 10 characters");
- passValid = false;
- }
- function isAlphanumeric(str) {
- return /^[a-zA-Z0-9]+$/.test(str);
- }
- if (!isAlphanumeric(password)) {
- console.log("Password must consist only of letters and digits");
- passValid = false;
- }
- function hasTwoDigits(str) {
- return (str.match(/[0-9]/g) || []).length >= 2;
- }
- if(!hasTwoDigits(password)) {
- console.log("Password must have at least 2 digits");
- passValid = false;
- }
- if (passValid) {
- console.log("Password is valid")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement