Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(args) {
- let password = args;
- let isPasswordLengthValid = isValidLength(password);
- if (!isPasswordLengthValid) {
- console.log("Password must be between 6 and 10 characters");
- }
- let isPasswordContentValid = isValidContent(password);
- if (!isPasswordContentValid) {
- console.log("Password must consist only of letters and digits");
- }
- let isPasswordCountDigitsValid = isValidCountDigits(password);
- if (!isPasswordCountDigitsValid) {
- console.log("Password must have at least 2 digits");
- }
- if (isPasswordLengthValid && isPasswordContentValid && isPasswordCountDigitsValid) {
- console.log("Password is valid");
- }
- }
- let isValidLength(password) {
- if (password.length() >= 6 && password.length() <= 10) {
- return true;
- } else {
- return false;
- }
- //return password.length() >= 6 && password.length() <= 10;
- }
- let isValidContent(password) {
- for (char symbol : password.toCharArray()) {
- if (!Character.isLetterOrDigit(symbol)) {
- return false;
- }
- }
- return true;
- }
- let isValidCountDigits(password) {
- let countDigits = 0;
- for (char symbol: password.toCharArray()) {
- if (Character.isDigit(symbol)) {
- countDigits++;
- }
- }
- /*if (countDigits >= 2) {
- return true;
- } else {
- return false;
- }*/
- return countDigits >= 2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement