Java tutorial
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static boolean isUserNameValid(String username) { boolean isValid = false; String expression = "^[a-zA-Z0-9_-]{5,10}$"; CharSequence inputStr = username; Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(inputStr); if (matcher.matches()) { isValid = true; } return isValid; } }