营业执照统一社会信用代码Java正则表达式

/**
 * 

ValidatorUtils

* * @version 1.0 * @author wangpf * @date 2018年8月8日 下午3:11:27 */ public class ValidatorUtils { /** * 手机号验证 * @param phone * @return 验证通过返回true */ public static boolean isMobile(String phone) { if(StringUtils.isEmpty(phone)) { return false; } String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$"; if(phone.length() != 11) { return false; }else { Pattern p = Pattern.compile(regex); Matcher m = p.matcher(phone); boolean isMatch = m.matches(); return isMatch; } } /** * 电话号码验证 * @param phone * @return 验证通过返回true */ public static boolean isPhone(String phone) { Pattern p1 = null, p2 = null; Matcher m = null; boolean b = false; p1 = Pattern.compile("^[0][0-9]{2,3}-?[0-9]{5,10}$"); // 验证带区号的 p2 = Pattern.compile("^[1-9]{1}[0-9]{5,8}$"); // 验证没有区号的 if (phone.length() > 9) { m = p1.matcher(phone); b = m.matches(); } else { m = p2.matcher(phone); b = m.matches(); } return b; } /** * 我国公民的身份证号码特点如下 * 1.长度18位 * 2.第1-17号只能为数字 * 3.第18位只能是数字或者x * 4.第7-14位表示特有人的年月日信息 * 请实现身份证号码合法性判断的函数,函数返回值: * 1.如果身份证合法返回0 * 2.如果身份证长度不合法返回1 * 3.如果第1-17位含有非数字的字符返回2 * 4.如果第18位不是数字也不是x返回3 * 5.如果身份证号的出生日期非法返回4 */ public static boolean validator(String id) { String str = "[1-9]{2}[0-9]{4}(19|20)[0-9]{2}" + "((0[1-9]{1})|(1[1-2]{1}))((0[1-9]{1})|([1-2]{1}[0-9]{1}|(3[0-1]{1})))" + "[0-9]{3}[0-9x]{1}"; Pattern pattern = Pattern.compile(str); return pattern.matcher(id).matches(); } /** * 营业执照 统一社会信用代码(15位) * @param license * @return */ public static boolean isLicense15(String license) { if(StringUtils.isEmpty(license)) { return false; } if(license.length() != 15) { return false; } String businesslicensePrex14 = license.substring(0,14);// 获取营业执照注册号前14位数字用来计算校验码 String businesslicense15 = license.substring(14, license.length());// 获取营业执照号的校验码 char[] chars = businesslicensePrex14.toCharArray(); int[] ints = new int[chars.length]; for(int i=0; i 1) { int ti = 0; int si = 0;// pi|11+ti int cj = 0;// (si||10==0?10:si||10)*2 int pj = 10;// pj=cj|11==0?10:cj|11 for (int i=0;i

 

你可能感兴趣的:(正则表达式)