Here you can find the source of passwordIsValid(String password)
Parameter | Description |
---|---|
password | the password. |
public static boolean passwordIsValid(String password)
//package com.java2s; import java.util.regex.Pattern; public class Main { private static final Pattern DIGIT_PATTERN = Pattern.compile(".*\\d.*"); private static final Pattern UPPERCASE_PATTERN = Pattern .compile(".*[A-Z].*"); /**/*from w w w. ja v a 2 s. co m*/ * Validates whether a password is valid. A password must: * <p> * <ul> * <li>Be between 8 and 80 characters long</li> * <li>Include at least one digit</li> * <li>Include at least one uppercase letter</li> * </ul> * * @param password the password. * @return true if the password is valid, false otherwise. */ public static boolean passwordIsValid(String password) { if (password == null || password.trim().length() < 8 || password.trim().length() > 35) { return false; } return DIGIT_PATTERN.matcher(password).matches() && UPPERCASE_PATTERN.matcher(password).matches(); } }