is Legal Password, length between 6.20 - Java java.util.regex

Java examples for java.util.regex:Match Password

Description

is Legal Password, length between 6.20

Demo Code

import java.util.regex.Pattern;

public class Main {

  public static void main(String[] argv) {
    String password = "java2s.com";
    System.out.println(isLegalPassword(password));
  }/* ww  w  .j a v a  2s.  c om*/

  public final static Pattern LEGAL_PASSWORD = Pattern.compile("^[a-zA-Z_0-9\\.`~!@#$%^&*()+-=/]{6,20}$");

  public static boolean isLegalPassword(String password) {
    return !isEmpty(password) && LEGAL_PASSWORD.matcher(password).matches();
  }

  public static boolean isEmpty(String str) {
    return str == null || str.trim().length() == 0 || str.trim().equalsIgnoreCase("null");
  }

}

Related Tutorials