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