In the project we use Java often have the use of authentication function, such as mobile phone number, password and other authentication.
To summarize, write a tool class to facilitate the use of the next time directly cited.
Package com.common.utils;
Import Org.apache.commons.lang3.StringUtils;
Import Java.util.regex.Matcher;
Import Java.util.regex.Pattern;
public class Validationutil {
public static Boolean IsMobile (String Mobile, Boolean isrequired) {
if (Stringutils.isblank (mobile) && isrequired) {
return false;
}
String regexp = "(1 (3|5|8) \\d|147|170|176|177|178) ((\\*{4}|\\d{4})) \\d{4}$";
Pattern pattern = pattern.compile (regexp);
Return Pattern.matcher (Mobile). matches ();
}
/**
* Verify Password
*/
public static Boolean validatepwd (String password) {
Pattern pattern = pattern.compile ("^[a-za-z0-9]{6,20}$");
return Pattern.matcher (password). matches ();
}
/**
* Verify that the phone number has an implicit number
*/
public static Boolean validatemobileishide (String mobile) {
Pattern pattern = pattern.compile ("^\\d+$");
Return Pattern.matcher (Mobile). matches ();
}
/**
* Verify that the Chinese language is included
*/
public static Boolean CONTAINSZHCN (String content) {
Pattern p = pattern.compile ("[\u4e00-\u9fa5]");
Matcher m = p.matcher (content);
if (M.find ()) {
return true;
}
return false;
}
public static void Main (string[] args) {
System.out.println (CONTAINSZHCN ("Chinese"));
}
}
Java Validation Tool class