Java regular expression tools, cell phone number Java regular expressions,
The latest mobile phone Java regular expressions, Java regular expressions Date
================================
© Copyright sweet potatoes Yao June 21, 2019
http://fanshuyao.iteye.com/
import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.lang.StringUtils; /** * Regular Expression Tools * */ public class RegUtils { /** * E-mail */ public static final String EMAIL = "^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$"; /** * cellphone number */ public static final String PHONE = "^(1[3-9]([0-9]{9}))$"; /** * Only Chinese */ public static final String CHINESE = "^[\\u4E00-\\u9FA5\\uF900-\\uFA2D]+$"; /** * Integer */ public static final String INTEGER = "^-?[1-9]\\d*$"; /** * Digital */ public static final String NUMBER = "^([+-]?)\\d*\\.?\\d+$"; /** * Positive integer */ public static final String INTEGER_POS = "^[1-9]\\d*$"; /** * Float */ public static final String FLOAT = "^([+-]?)\\d*\\.\\d+$"; /** * Positive 浮点 number */ public static final String FLOAT_POS = "^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*$"; /** * Is positive integer numbers, including zero (00, 01 non-digital) */ public static final String INTEGER_WITH_ZERO_POS = "^(([0-9])|([1-9]([0-9]+)))$"; /** * Is an integer number, including positive and negative integers, including zero (00, 01, non-digital) */ public static final String NUMBER_WITH_ZERO = "^((-)?(([0-9])|([1-9]([0-9]+))))$"; /** * Whether the string of digits */ public static final String NUMBER_TEXT = "^([0-9]+)$"; /** * Digital (integer, 0, floating point), can determine whether the amount can also be negative */ public static final String NUMBER_ALL = "^((-)?(([0-9])|([1-9][0-9]+))(\\.([0-9]+))?)$"; /** * QQ, 5-14 bits */ public static final String QQ = "^[1-9][0-9]{4,13}$"; /** * IP address */ public static final String IP = "((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))"; /** Zip Code * */ public static final String POST_CODE = "[1-9]\\d{5}(?!\\d)"; /** * Normal Date */ public static final String DATE = "^[1-9]\\d{3}-((0[1-9])|(1[0-2]))-((0[1-9])|([1-2][0-9])|(3[0-1]))$"; /** * Complex date, does not distinguish between a leap year, February * Date format: 2017-10-19 * Or 2017/10/19 * Or 2017.10.19 * Or October 19, 2017 * Maximum 31 days of the month: (((01 | 03 | 05 | 07 | 08 | 10 | 12)) - ((0 [1-9]) | ([1-2] [0-9]) | ( 3 [0-1]))) * Up to 30 days of the month: (((04 | 06 | 11)) - ((0 [1-9]) | ([1-2] [0-9]) | (30))) * Maximum 29 days of the month: (02 - ((0 [1-9]) | ([1-2] [0-9]))) */ public static final String DATE_COMPLEX = "^ (([1-2] \\ d {3}) (- |. / | | years) ((((01 | 03 | 05 | 07 | 08 | 10 | 12)) (- |. / | | month) ((0 [1-9]) | ([1-2] [0-9]) | (3 [0-1]))) | (((04 | 06 | 11)) (- |. / | | month) ((0 [1-9]) | ([1-2] [0-9]) | (30))) | (02 - ((0 [1- 9]) | ([1-2] [0-9])))) (Japan)) $ ";? /** * Complex date, the distinction between a leap year, February * This check can distinguish between leap year date of February, in the following format: 2017-10-19 * (See: http: //www.jb51.net/article/50905.htm) * ^((?!0000)[0-9]{4}-((0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-8])|(0[13-9]|1[0-2])-(29|30)|(0[13578]|1[02])-31)|([0-9]{2}(0[48]|[2468][048]|[13579][26])|(0[48]|[2468][048]|[13579][26])00)-02-29)$ */ public static final String DATE_COMPLEX_LEAP_YEAR = "^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$"; /** * Regular expressions check, in line with returns True * @Param regex regular expression * @Param content check content * @return */ public static boolean isMatch(String regex, CharSequence content){ return Pattern.matches(regex, content); } /** * Check phone number * @param mobile * @return */ public static final boolean isMoblie(String mobile){ boolean flag = false; if (null != mobile && !mobile.trim().equals("") && mobile.trim().length() == 11) { Pattern pattern = Pattern.compile(PHONE); Matches matches = pattern.matcher (mobile.trim ()); flag = matcher.matches(); } return flag; } /** * Check-mail * @param value * @return */ public static final boolean isEmail(String value){ boolean flag = false; if (null != value && !value.trim().equals("")) { Pattern pattern = Pattern.compile(EMAIL); Matcher matches = pattern.matcher (value.trim ()); flag = matcher.matches(); } return flag; } /** * Check password * @param password * @Return the length of the line with returns true, false otherwise */ public static final boolean isPassword(String password){ boolean flag = false; if (null != password && !password.trim().equals("")) { password = password.trim(); if(password.length() >= 6 && password.length() <= 30){ return true; } } return flag; } /** * Check phone code * @param value * @Return in line with the regular expression returns true, false otherwise */ public static final boolean isPhoneValidateCode(String value){ boolean flag = false; if (null != value && !value.trim().equals("")) { Pattern pattern = Pattern.compile("^8\\d{5}$"); Matcher matches = pattern.matcher (value.trim ()); flag = matcher.matches(); } return flag; } /** * Determine whether all capital letters * @Param Cycle * @return */ public static boolean isUpperCase(String str){ if(StringUtils.isEmpty(str)){ return false; } String reg = "^[A-Z]$"; return isMatch(reg,str); } /** * Determine whether all lowercase letters * @Param Cycle * @return */ public static boolean isLowercase(String str){ if(StringUtils.isEmpty(str)){ return false; } String reg = "^[a-z]$"; return isMatch(reg,str); } /** * Are ip address * @Param Cycle * @return */ public static boolean isIP(String str){ if(StringUtils.isEmpty(str)){ return false; } return isMatch(IP, str); } /** * Comply returns true, distinguish between 30 and 31 days and a leap year in February (the most stringent check), the format 2017-10-19 * @Param Cycle * @return */ public static boolean isDate(String str){ if(StringUtils.isEmpty(str)){ return false; } return isMatch(DATE_COMPLEX_LEAP_YEAR, str); } /** * Simple calibration date, less stringent * @Param Cycle * @return */ public static boolean isDateSimple(String str){ if(StringUtils.isEmpty(str)){ return false; } return isMatch(DATE, str); } /** * Distinguish between 30 and 31 days, but does not distinguish leap year in February * @Param Cycle * @return */ public static boolean isDateComplex(String str){ if(StringUtils.isEmpty(str)){ return false; } return isMatch(DATE_COMPLEX, str); } /** * Is determined whether the number string, such as 0011,10101,01 * @Param Cycle * @return */ public static boolean isNumberText(String str){ if(StringUtils.isEmpty(str)){ return false; } return isMatch(NUMBER_TEXT, str); } /** * Determine all types of digital, digital (integer, 0, floating point), you can determine whether the amount can also be negative * @Param Cycle * @return */ public static boolean isNumberAll(String str){ if(StringUtils.isEmpty(str)){ return false; } return isMatch(NUMBER_ALL, str); } /** * Is positive integer numbers, including zero (00, 01 non-digital) * @Param Cycle * @return */ public static boolean isIntegerWithZeroPos(String str){ if(StringUtils.isEmpty(str)){ return false; } return isMatch(INTEGER_WITH_ZERO_POS, str); } /** * Is an integer, including positive and negative integers, including zero (00, 01, non-digital) * @Param Cycle * @return */ public static boolean isIntegerWithZero(String str){ if(StringUtils.isEmpty(str)){ return false; } return isMatch(NUMBER_WITH_ZERO, str); } /** * Comply return true, QQ, 5-14 bits * @Param Cycle * @return */ public static boolean isQQ(String str){ if(StringUtils.isEmpty(str)){ return false; } return isMatch(QQ, str); } public static void main(String[] args) { System.out.println(isMoblie("13430800244")); System.out.println(isMoblie("17730800244")); System.out.println(isMoblie("17630800244")); System.out.println(isMoblie("14730800244")); System.out.println(isMoblie("18330800244")); System.out.println(isMoblie("19330800244")); System.out.println(isMoblie("1333000244")); } }
================================
© Copyright sweet potatoes Yao June 21, 2019
http://fanshuyao.iteye.com/