Java tutorial
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static boolean checkPassword(String password) { Pattern pattern = Pattern.compile(".*[a-zA-Z].*[0-9]|.*[0-9].*[a-zA-Z]"); //Pattern pattern = Pattern.compile("^[A-Za-z0-9]{6,20}$"); Matcher matcher = pattern.matcher(password); return matcher.matches(); } }