鑒於歷史原因,營業執照注冊號為15位,但是自2016年7月1日后,“三證合一、一照一碼”,將營業執照正副本照面加載的15位注冊號調整為18位的法人和其他組織統一社會信用代碼(個體工商戶營業執照除外)。
為了兼顧,同時使用兩種編碼的校驗,
15位編碼的校驗依據GS15—2006 《工商行政管理市場主體注冊號編制規則》,
代碼結構工商注冊號由14位數字本體碼和1位數字校驗碼組成,其中本體碼從左至右依次為:6位首次登記機關碼、8位順序碼,1位數字校驗碼組成。
說明可參考:http://blog.sina.com.cn/s/blog_76e84df30101eb63.html
18位編碼的校驗依據GB 32100-2015 《法人和其他組織統一社會信用代碼編碼規則》,
統一代碼由十八位阿拉伯數字或大寫英文字母(不使用I、O、Z、S、V)組成,包括第1位登記管理部門代碼、第2位機構類別代碼、第3位~第8位登記管理機關行政區划碼、第9位~第17位主體標識碼(組織機構代碼)、第18位校驗碼五個部門。
15位編碼校驗代碼如下:
--- 15位代碼有部分錯誤,請只參考方法:具體判斷邏輯還請參考國標,文檔地址:
http://wenku.baidu.com/link?url=1i4slMmKov6LncwLAwa-VmJmAwRwIkgcK-xzls2uOnuJzS7wrsG_mjDdVOVbQzG0ZIQknNoHLTj8lqhhSuqDNZjHVLzsdDEQFbX4gD5KB67
/** * Desc: 營業執照編號 驗證 * Created 2016/5/14. */ public class Regex_BusinessLicenseNumber { /** * 營業執照注冊號校驗正確返回碼 */ public static String isBusinesslicense = "true"; private static String error_Businesslicense_Empty = "請輸入營業執照注冊號"; public static String error_Businesslicense = "您輸入的營業執照注冊號有誤,請核對后再輸!"; public static String error_Businesslicense_No = "您輸入的營業執照注冊號不足15位,請核對后再輸!"; static String test = "110108000000016" ;// 營業執照號 public static void main(String[] args ){ System.out.println(test); isBusinesslicense(test); } /** * 校驗 營業執照注冊號 * @param businesslicense * @return */ public static String isBusinesslicense(String businesslicense){ if ("".equals(businesslicense)||" ".equals(businesslicense)){ System.out.println(error_Businesslicense_Empty); return error_Businesslicense_Empty; }else if(businesslicense.length()!=15){ System.out.println(error_Businesslicense_No); return error_Businesslicense_No; } String businesslicensePrex14 = businesslicense.substring(0,14);// 獲取營業執照注冊號前14位數字用來計算校驗碼 String businesslicense15 = businesslicense.substring(14,businesslicense.length());// 獲取營業執照號的校驗碼 char[] chars = businesslicensePrex14.toCharArray(); int[] ints = new int[chars.length]; for(int i=0; i<chars.length;i++){ ints[i] = Integer.parseInt(String.valueOf(chars[i])); } getCheckCode(ints); if(businesslicense15.equals(getCheckCode(ints)+"")){// 比較 填寫的營業執照注冊號的校驗碼和計算的校驗碼是否一致 System.out.println(isBusinesslicense); return isBusinesslicense; } System.out.println(error_Businesslicense); return error_Businesslicense; } /** * 獲取 營業執照注冊號的校驗碼 * @param ints * @return */ private static int getCheckCode(int[] ints){ if (null != ints && ints.length > 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<ints.length;i++) { ti = ints[i]; pj = (cj % 11) == 0 ? 10 : (cj % 11); si = pj + ti; cj = (0 == si % 10 ? 10 : si % 10) * 2; if (i == ints.length-1) { pj = (cj % 11) == 0 ? 10 : (cj % 11); return pj == 1 ? 1 : 11 - pj; } } } return -1; } }
18位編碼校驗代碼如下:
/** * Created by Administrator on 2016/10/23. */ function checkCode(){ var code = document.getElementById("zuzhiCode").value; if(code.length != 18){ alert("社會信用代碼長度錯誤!"); return false; } var reg = /^([0-9ABCDEFGHJKLMNPQRTUWXY]{2})([0-9]{6})([0-9ABCDEFGHJKLMNPQRTUWXY]{9})([0-9Y])$/; if(!reg.test(code)){ alert("社會信用代碼校驗錯誤!"); return false; } var str = '0123456789ABCDEFGHJKLMNPQRTUWXY'; var ws =[1,3,9,27,19,26,16,17,20,29,25,13,8,24,10,30,28]; var codes = new Array(); codes[0] = code.substr(0,code.length-1); codes[1] = code.substr(code.length-1,code.length); var sum = 0; for(var i=0;i<17;i++){ sum += str.indexOf(codes[0].charAt(i)) * ws[i]; } var c18 = 31 - (sum % 31); if(c18 == 31){ alert("第18位 == 31"); c18 = 'Y'; }else if(c18 == 30){ alert("第18位 == 30"); c18 = '0'; } if(c18 != codes[1]){ alert("社會信用代碼有誤!"+c18); return false; } }