驗證企業信用代碼
阿新 • • 發佈:2019-04-03
nco 驗證 red div log ota 加權 false style
1 function CheckSocialCreditCode(Code) { 2 var patrn = /^[0-9A-Z]+$/; 3 //18位校驗及大寫校驗 4 if ((Code.length != 18) || (patrn.test(Code) == false)) { 5 console.info("不是有效的統一社會信用編碼!"); 6 return false; 7 } 8 else { 9 var Ancode;//統一社會信用代碼的每一個值 10 varView CodeAncodevalue;//統一社會信用代碼每一個值的權重 11 var total = 0; 12 var weightedfactors = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];//加權因子 13 var str = ‘0123456789ABCDEFGHJKLMNPQRTUWXY‘; 14 //不用I、O、S、V、Z 15 for (var i = 0; i < Code.length - 1; i++) { 16 Ancode = Code.substring(i, i + 1);17 Ancodevalue = str.indexOf(Ancode); 18 total = total + Ancodevalue * weightedfactors[i]; 19 //權重與加權因子相乘之和 20 } 21 var logiccheckcode = 31 - total % 31; 22 if (logiccheckcode == 31) { 23 logiccheckcode = 0; 24 } 25 varStr = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,T,U,W,X,Y"; 26 var Array_Str = Str.split(‘,‘); 27 logiccheckcode = Array_Str[logiccheckcode]; 28 var checkcode = Code.substring(17, 18); 29 if (logiccheckcode != checkcode) { 30 console.info("不是有效的統一社會信用編碼!"); 31 return false; 32 }else{ 33 console.info("yes"); 34 return true; 35 } 36 return true; 37 } 38 }
驗證企業信用代碼