Java tutorial
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static boolean passwordFormat(String password) { if (password == null) return false; String regular = "^[a-zA-Z0-9_]{6,16}$"; Pattern pattern = Pattern.compile(regular); Matcher matcher = pattern.matcher(password); if (!matcher.matches()) { return false; } return true; } }