Package com.office.utility;
Import Java.util.regex.Pattern;
/**
* Validator: Use regular expression to check the mailbox, mobile phone number, etc.
*
* @author Liujiduo
*
*/
public class Validator {
/**
* Regular expression: Verify user name
*/
public static final String regex_username = "^[a-za-z]\\w{5,17}$";
/**
* Regular expression: Verify password
*/
public static final String Regex_password = "^[a-za-z0-9]{6,16}$";
/**
* Regular expression: Verify the phone number
*/
public static final String regex_mobile = "^ ((13[0-9]) | ( 15[^4,\\D]) | (18[0,5-9])) \\d{8}$ ";
/**
* Regular expression: Verify Mailbox
*/
public static final String Regex_email = "^ ([a-z0-9a-z]+[-|\\.]?) +[a-z0-9a-z]@ ([a-z0-9a-z]+ (-[a-z0-9a-z]+) \ \.) +[a-za-z]{2,}$ ";
/**
* Regular Expressions: Validating Chinese characters
*/
public static final String Regex_chinese = "^[\u4e00-\u9fa5],{0,}$";
/**
* Regular expression: Verify ID
*/
public static final String Regex_id_card = "(^\\d{18}$) | (^\\d{15}$) ";
/**
* Regular expression: Verify URL
*/
public static final String Regex_url = "http (s)?:/ /([\\w-]+\\.) +[\\w-]+ (/[\\w-./?%&=]*)? ";
/**
* Regular expression: Verify IP Address
*/
public static final String regex_ip_addr = "(25[0-5]|2[0-4]\\d|[ 0-1]\\d{2}| [1-9]?\\d) ";
/**
* Verify user name
*
* @param username
* @return Checksum returns TRUE, otherwise false
*/
public static Boolean Isusername (String username) {
Return Pattern.matches (Regex_username, USERNAME);
}
/**
* Check Password
*
* @param password
* @return Checksum returns TRUE, otherwise false
*/
public static Boolean Ispassword (String password) {
Return Pattern.matches (Regex_password, PASSWORD);
}
/**
* Check the phone number
*
* @param Mobile
* @return Checksum returns TRUE, otherwise false
*/
public static Boolean IsMobile (String mobile) {
Return Pattern.matches (Regex_mobile, MOBILE);
}
/**
* Check Mailbox
*
* @param Email
* @return Checksum returns TRUE, otherwise false
*/
public static Boolean isemail (String email) {
Return Pattern.matches (Regex_email, EMAIL);
}
/**
* Check Kanji
*
* @param Chinese
* @return Checksum returns TRUE, otherwise false
*/
public static Boolean Ischinese (String Chinese) {
Return pattern.matches (Regex_chinese, Chinese);
}
/**
* Verify ID
*
* @param idcard
* @return Checksum returns TRUE, otherwise false
*/
public static Boolean Isidcard (String idcard) {
Return Pattern.matches (Regex_id_card, Idcard);
}
/**
* Check URL
*
* @param URL
* @return Checksum returns TRUE, otherwise false
*/
public static Boolean isurl (String URL) {
Return Pattern.matches (Regex_url, URL);
}
/**
* Verify IP Address
*
* @param ipaddr
* @return
*/
public static Boolean isipaddr (String ipaddr) {
Return Pattern.matches (REGEX_IP_ADDR, ipaddr);
}
public static void Main (string[] args) {
String username = "FDSDFSDJ";
System.out.println (Validator.isusername (username));
System.out.println (Validator.ischinese (username));
}
}
Online search for the regular verification mailbox phone and other code