ID Number Verification Bank card number verification

Source: Internet
Author: User

Identification Number Verification

/* approval System ID card verification * ID Card 15-bit encoding rules: DDDDDD YYMMDD xx p * Dddddd:6 bit area code * YYMMDD: Year of birth (two years) month day, such as: 910215 * XX: Sequential encoding, System generation, unable to determine * p: gender, odd male, even female * ID 18-bit encoding rule: dddddd yyyymmdd xxx y * dddddd:6 Location Code * YYYYMMD  D: Year of birth (four years) month day, such as: 19910215 * XXX: Sequential encoding, System generation, cannot be determined, odd male, even female * y: Check code, this bit value can be calculated by the first 17 digits * * The first 17 digits weighting factor for Wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2] * Verify bit Y = [1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2] * If the verification code just Good is 10, in order to ensure that the identity card is 18, then the 18th bit will use X to replace the * check digit calculation formula: y_p = mod (∑ (AIXWI), one) * I for the ID number 1 ... 17 bits; Y_p is the check Code array location for the checksum y * /      function isidcardno(idcard){         Regular Expressions for//15-bit and 18-bit ID numbers         varregidcard=/^ (^[1-9]\d{7} ((0\d) | ( 1[0-2]) (([0|1|2]\d) |3[0-1]) \d{3}$) | (^[1-9]\d{5}[1-9]\d{3} ((0\d) | ( 1[0-2]) (([0|1|2]\d) |3[0-1]) ((\d{4}) |\d{3}[xx]) $) $/;//If you pass this verification, the ID card format is correct, but the accuracy must be calculated         if(Regidcard.test (Idcard)) {if(idcard.length== -){varIdcardwi=New Array(7,9,Ten,5,8,4,2,1,6,3,7,9,Ten,5,8,4,2);//Save the first 17-bit weighting factor in the array                 varidcardy=New Array(1,0,Ten,9,8,7,6,5,4,3,2);//This is the 11-bit remainder, the verification code, which is divided by 11, which may result in an array of                 varidcardwisum=0;//used to hold the sum of the first 17 digits after the weighted factor                  for(varI=0;i< -; i++) {idcardwisum+=idcard.substring (i,i+1) *idcardwi[i]; }varidcardmod=idcardwisum% One;//Calculate the location of the array where the checksum is located                 varIdcardlast=idcard.substring ( -);//Get last ID number                 //If equal to 2, then the check code is 10, ID number The last one should be x                 if(idcardmod==2){if(idcardlast=="X"|| idcardlast=="x"){//alert ("Congratulations are verified!") ");                         return true; }Else{//alert ("ID card number is wrong! ");                             return false; }                     }Else{//Use the calculated verification code to match the last identity card number, if consistent, the instructions passed, otherwise it is invalid ID number                         if(Idcardlast==idcardy[idcardmod]) {//alert ("Congratulations are verified!") ");                             return true; }Else{//alert ("ID card number is wrong! ");                         return false; }                 }                 }             }Else{//alert ("ID card format is incorrect!");                 return false; }     }

Bank card number Verification

 //luhm Check rule: 16-digit bank card number (19-bit generic):      //1. The 15 (or 18) position card number without the check digit is numbered 1 through 15 (18) from the right, and the number on the odd digit number is multiplied by 2.       //2. Add all 10 bits of the singular product, plus the numbers on all even digits.       //3. The addition and calibration potentials are divisible by 10.       //method steps are clear and easy to understand and need to be referenced on the page jquery.js      //bankno for the bank card number banknoinfo the DIV or other control that displays the cue information       function luhmcheck(bankno){          varLastnum=bankno.substr (bankno.length-1,1);//Remove the last one (compare with Luhm)          varFIRST15NUM=BANKNO.SUBSTR (0, bankno.length-1);//Top 15 or 18 bits          varNewarr=New Array(); for(vari=first15num.length-1; i>-1; i--) {//First 15 or 18 bit in reverse in an arrayNewarr.push (First15num.substr (i,1)); }vararrjishu=New Array();//Odd digit * * The product <9          varArrjishu2=New Array();//Odd digit * * The product >9          vararroushu=New Array();//Even digit array           for(varj=0; j<newarr.length;j++) {if((j+1)%2==1){//odd digit                  if(parseint(Newarr[j]) *2<9) Arrjishu.push (parseint(Newarr[j]) *2);ElseArrjishu2.push (parseint(Newarr[j]) *2); }Else //Even digitArroushu.push (Newarr[j]); }varjishu_child1=New Array();//Odd digit * * >9 after the split of the array single digit          varJishu_child2=New Array();//Odd digit * * >9 the array after the split 10-digit           for(varH=0; h<arrjishu2.length;h++) {Jishu_child1.push (parseint(Arrjishu2[h])%Ten); Jishu_child2.push (parseint(Arrjishu2[h])/Ten); }varsumjishu=0;//Odd digit < 9 array of the sum          varsumoushu=0;sum of//even bit arrays          varsumjishuchild1=0;//Odd digit * * >9 the sum of the single digits of the array after the split          varSumjishuchild2=0;//Odd digit * * >9 the sum of the array 10 digits after the partition          varSumtotal=0; for(varm=0; m<arrjishu.length;m++) {sumjishu=sumjishu+parseint(Arrjishu[m]); } for(varn=0; n<arroushu.length;n++) {sumoushu=sumoushu+parseint(Arroushu[n]); } for(varp=0;p <jishu_child1.length;p++) {sumjishuchild1=sumjishuchild1+parseint(Jishu_child1[p]); sumjishuchild2=sumjishuchild2+parseint(Jishu_child2[p]); }//Calculate sumSumtotal=parseint(Sumjishu) +parseint(Sumoushu) +parseint(sumJiShuChild1) +parseint(SUMJISHUCHILD2);//Calculate LUHM value          vark=parseint(sumtotal)%Ten==0?Ten:parseint(sumtotal)%Ten;varluhm=Ten-K;if(LASTNUM==LUHM) {//$ ("#banknoInfo"). HTML ("Luhm authentication passed");          return true; }Else{//$ ("#banknoInfo"). HTML ("bank card number must conform to LUHM checksum");          return false; }              }

ID Number Verification Bank card number verification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.