Java tutorial
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { private static final String PASSWORD_REGULAR = "^[a-zA-Z0-9]{6,20}$"; public static boolean isPasswordValid(String password) { Pattern p = Pattern.compile(PASSWORD_REGULAR); Matcher m = p.matcher(password); return m.matches(); } }