Java tutorial
//package com.java2s; import android.text.TextUtils; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static boolean isUserNameCorrect(String userName) { if (!TextUtils.isEmpty(userName)) { Pattern pattern = Pattern.compile("^[0-9a-zA-Z_]{6,20}$"); Matcher matcher = pattern.matcher(userName); return matcher.find(); } return false; } }