18-bit ID card verification algorithm
ID card verification code algorithm
How to generate ID card verification code:
∑(ai×Wi)(mod11)
i: indicates the position number including the verification code from the left;
ai represents the number character value at the i-th position;
The weighting factor at the i-th position of Wi, its value Wi=mod(power(2,(n-1)),11)
i181716151413121110987654321
Wi79105842163791058421
Corresponding verification code:
∑(ai×WI)(mod11)012345678910
Verify code character value ai10X98765432
Here is the check function:
FUNCTIONsfzjy(num)
iflen(num)=15then
cID=left(num,6)&"19"&right(num,9)
elseiflen(num)=17orlen(num)=18then
cID=left(num,17)
endif
nSum=mid(cID,1,1)*7
nSum=nsum+mid(cID,2,1)*9
nSum=nsum+mid(cID,3,1)*10
nSum=nsum+mid(cID,4,1)*5
nSum=nsum+mid(cID,5,1)*8
nSum=nsum+mid(cID,6,1)*4
nSum=nsum+mid(cID,7,1)*2
nSum=nsum+mid(cID,8,1)*1
nSum=nsum+mid(cID,9,1)*6
nSum=nsum+mid(cID,10,1)*3
nSum=nsum+mid(cID,11,1)*7
nSum=nsum+mid(cID,12,1)*9
nSum=nsum+mid(cID,13,1)*10
nSum=nsum+mid(cID,14,1)*5
nSum=nsum+mid(cID,15,1)*8
nSum=nsum+mid(cID,16,1)*4
nSum=nsum+mid(cID,17,1)*2
'* Calculate the check bit
check_number=12-nsummod11
Ifcheck_number=10thencheck_number="X"elseIfcheck_number=12thencheck_number="1"elseifcheck_number=11thencheck_number="0"Endifsfzjy=check_number
Endfunction
Other verifications:
Gender and date of birth:
sfznum=ID number
lenx=len(sfznum)
iflenx=15then
yy="19"&mid(xian,7,2)
mm=mid(xian,9,2)
dd=mid(xian,11,2)
aa=mid(xian,15,1)'15-digit identity card can be ranked 15th, can be divided into 2 women
endif
iflenx=18then
yy=mid(xian,7,4)
mm=mid(xian,11,2)
dd=mid(xian,13,2)