- packagecom.chinagas.org.common.utils;
- importjava.util.regex.Matcher;
- importjava.util.regex.Pattern;
- publicfinalclassRegUtils{
- /*------------------正则表达式---------------------*/
- /**
- *邮箱
- */
- staticfinalStringREGEX_EMAIL="^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$";
- *手机号码
- finalStringREGEX_PHONE="^13[0-9]{9}|15[012356789][0-9]{8}|18[0-9]{9}|(14[57][0-9]{8})|(17[015678][0-9]{8})$";
- *仅中文
- finalStringREGEX_CHINESE="^[\\u4E00-\\u9FA5\\uF900-\\uFA2D]+$";
- *整数
- finalStringREGEX_INTEGER="^-?[1-9]\\d*$";
- *数字
- finalStringREGEX_NUMBER="^([+-]?)\\d*\\.?\\d+$";
- *正整数
- finalStringREGEX_INTEGER_POS="^[1-9]\\d*$";
- *浮点数
- finalStringREGEX_FLOAT="^([+-]?)\\d*\\.\\d+$";
- *正浮点数
- finalStringREGEX_FLOAT_POS="^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*$";
- *字母
- finalStringREGEX_LETTER="^[A-Za-z]+$";
- *大写字母
- finalStringREGEX_LETTER_UPPERCASE="^[A-Z]+$";
- *小写字母
- finalStringREGEX_LETTER_LOWERCASE="^[a-z]+$";
- *邮编
- finalStringREGEX_ZIPCODE="^\\d{6}$";
- *ipv4地址
- finalStringREGEX_IP4="^(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)$";
- *图片
- finalStringREGEX_PICTURE="(.*)\\.(jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga)$";*压缩文件
- finalStringREGEX_RAR="(.*)\\.(rar|zip|7zip|tgz)$";
- *QQ号码,最短5位,最长15位数字
- finalStringREGEX_QQ="^[1-9]\\d{4,14}$";
- *日期(yyyy-MM-dd)
- finalStringREGEX_DATE="^\\d{4}\\D+\\d{2}\\D+\\d{2}$";
- *日期(yyyy-MM-dd),精确,能检查到2月及31号
- finalStringREGEX_DATE_PRECISE="^((\\d{2}(([02468][048])|([13579][26]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][1235679])|([13579][01345789]))[\\-\\/\\s]?((((0?[13578])|(1[02]))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\\-\\/\\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\\-\\/\\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))";
- *时间(HH:mm:ss或HH:mm)
- finalStringREGEX_TIME="^((([0-1][0-9])|2[0-3]):[0-5][0-9])(:[0-5][0-9])?$";
- *校验手机号码
- *@parammobile
- *@return
- *@authorlqyao
- booleanisMoblie(Stringmobile){
- booleanflag=false;
- if(null!=mobile&&!mobile.trim().equals("")&&mobile.trim().length()==11){
- Patternpattern=Pattern.compile(REGEX_PHONE);
- Matchermatcher=pattern.matcher(mobile.trim());
- flag=matcher.matches();
- }
- returnflag;
- *校验邮箱
- *@paramvalue
- booleanisEmail(Stringvalue){
- null!=value&&!value.trim().equals("")){
- Patternpattern=Pattern.compile(REGEX_EMAIL);
- Matchermatcher=pattern.matcher(value.trim());
- *校验密码
- *@parampassword
- *@return长度符合返回true,否则为false
- *@since2015-09-24
- booleanisPassword(Stringpassword){
- null!=password&&!password.trim().equals("")){
- password=password.trim();
- if(password.length()>=6&&password.length()<=30){
- returntrue;
- *校验手机验证码
- *@return符合正则表达式返回true,否则返回false
- booleanisPhoneValidateCode(Stringvalue){
- Patternpattern=Pattern.compile("^8\\d{5}$");
- *正则表达式校验,符合返回True
- *@paramregex正则表达式
- *@paramcontent校验的内容
- *@authorlqy
- booleanisMatch(Stringregex,CharSequencecontent){
- returnPattern.matches(regex,content);
- booleanisUpperCase(Stringstr){
- if(StrUtils.isEmpty(str)){
- Stringreg="^[A-Z]$";
- returnisMatch(reg,str);
- }