Java tutorial
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static boolean checkString(String string) { String check = "^[0-9A-Za-z_]{6,20}$"; Pattern regex = Pattern.compile(check); Matcher matcher = regex.matcher(string.trim()); boolean isMatched = matcher.matches(); return isMatched; } }