1.java用户校验

public class UsernameValidator {

private Pattern pattern;

private Matcher matcher;

private static final String USERNAME_PATTERN ="^[a-z0-9_-][3,15]$";

public UsernameValidator(){

pattern = Pattern.compile(USERNAME_PATTERN);

}

/*

* 验证用户名与正则表达式

* @param用户名用户名进行验证

* @return真正有效的用户名、虚假无效的用户名

*/

public boolean validate(final String username){

matcher = pattern.matcher(username);

return matcher.matches();

}

}


你可能感兴趣的:(1.java用户校验)