ID card number verification

Source: Internet
Author: User

 

ID card number verification

Http://blog.donews.com/gxgx/category/39640.aspx? Pagenumber = 1

 

/*-------------------------------------------------------------------------------
* Function name: Boolean gf_check_identity (string as_identity)
* Function: verify the correctness of the ID card number input (you can determine the 18th-bit verification bit of the ID card number .)
* Parameter description: String as_identity ID card number
* Return value: True
* False failed
* Call example: gf_check_identity ('20140901 ')
* Modification date:
* Modifier: tecsun
*--------------------------------------------------------------------------------*/
String ls_identity_no
String ls_year, ls_month, ls_day, ls_date
String ls_today
Long ll_year
Long ll_identity_no_len

Ls_identity_no = as_identity
Ls_today = string (today (), 'yyyy/MM/dd ')

Ll_identity_no_len = Len (ls_identity_no)

If ls_identity_no = ''then
MessageBox ("system prompt", "ID card number cannot be blank !! ", Stopsign !, OK !)
Return false
Elseif ll_identity_no_len <> 15 and ll_identity_no_len <> 18 then
MessageBox ("system prompt", "the number of digits in the ID card is incorrect. Check the input information !! ", Stopsign !, OK !)
Return false
End if

If ll_identity_no_len = 15 then // If the ID card is 15, the 15-digit year = 19 **
Ls_year = mid (ls_identity_no, 7, 2)
Ls_month = mid (ls_identity_no, 9, 2)
Ls_day = mid (ls_identity_no, 11, 2)
Ls_year = '19' + ls_year // year is only 20 century
Ls_date = ls_year + '/' + ls_month + '/' + ls_day
Else
Ls_year = mid (ls_identity_no, 7, 4)

If left (ls_year, 2) <> '19' and left (ls_year, 2) <> '20' then
MessageBox ("system prompt", "The Birth Year in the ID card number is incorrect. Please enter it again! ", Stopsign !, OK !)
Return false
End if

Ls_month = mid (ls_identity_no, 11, 2)
Ls_day = mid (ls_identity_no, 13, 2)
Ls_date = ls_year + '/' + ls_month + '/' + ls_day
End if

If ls_month> '12' then
MessageBox ("system prompt", "the birth month in the ID card number cannot exceed 12. Please enter", stopsign !, OK !)
Return false
Elseif ls_month <= '00' then
MessageBox ("system prompt", "the birth month in the ID card number cannot be less than 01. Please enter", stopsign !, OK !)
Return false
End if

If ls_day <= '00' then
MessageBox ("system prompt", "the birth date of the ID card number is less than 01. Please enter it again! ", Stopsign !, OK !)
Return false
End if

Choose case ls_month
Case '01 ', '03', '05', '07 ', '08', '10', '12' // processing of the big month
If ls_day> '31' then
MessageBox ("system prompt", "the birth date of the ID card number is later than 31. Please enter it again! ", Stopsign !, OK !)
Return false
End if

Case '04 ', '06', '05', '09 ', '11' // processing of the month

If ls_day> '30' then
MessageBox ("system prompt", "the birth date of the ID card number is greater than 30 (No 31 days this month). Please enter it again! ", Stopsign !, OK !)
Return false
End if

Case '02' // processing of the Year of the normal and the LEAP

Ll_year = long (ls_year)

If (mod (ll_year, 4) = 0 and Mod (ll_year, 100) <> 0) or (mod (ll_year, 400) = 0) Then // leap year, january cannot exceed 29 days
If ls_day> '29' then
MessageBox ("system prompt", "no" + ls_day + "day in March of the leap year", please enter the date of birth again! ", Stopsign !, OK !)
Return false
End if
Else // February cannot exceed 28 days
If ls_day> '28' then
MessageBox ("system prompt", "there is no" + ls_day + "day in August of the same year. Please enter the date of birth again! ", Stopsign !, OK !)
Return false
End if
End if

End choose

If ls_date> ls_today then
MessageBox ("system prompt", "the birth date of the ID card number is less than the registration date. If this is not the case, enter it again! ", Stopsign !, OK !)
Return false
End if

/* = ========================================================== =====+/
According to the civil identity number in the national standard GB11643-1999 of the People's Republic of China
Requires that the citizenship number is a feature combination code, which is verified by a 17-digit local code and a digit.
Code. The sorting order is from left to right: six-digit address location code, eight-digit output
Birth date code, three digit sequence code, and one digit verification code.

Address location code: indicates the administrative area code of the county (city, district) where the resident's permanent residence is located.

Date of birth: indicates the year, month, and day of birth of a resident. The year is represented by four digits,
There is no separator between years, months, and days.

Number Sequence Code: indicates that the same address area code is within the range of the region, for the same year with the same month
The sequence number specified by the person born on the day. An odd number is assigned to men, and an even number is given to women.

Digit verification code: based on the preceding 17-digit code, the calibration is performed according to ISO 7064: 1983.mod 11-2.
The verification code calculated by the Verification code. It is composed of (, 9, X.

The following example shows how to use the code to implement the calculation method.

Formula: AX = (Σ (AI x WI) (mod 11 ).............................. (1)

I ---- indicates the serial number of the characters in the ID card number from right to left, including the verification code;
AI ---- indicates the number at position I;
Ax ---- value of the digital verification code;
Wi ---- indicates the weighting factor at position I;
Formula: Wi = (2 ^ (I-1) (mod 11 ).............................. (2)

Set a male citizenship number to 51310119820113001 and get the variables:

I18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1

Ai5 1 3 1 0 1 1 9 8 2 0 1 1 3 0 1 ax
The following formula is available:
Wi7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 1

AI x wi 35 9 30 5 0 4 2 9 48 6 0 9 10 15 0 2 A1

Calculated according to formula (1:

SIGMA (AI x WI) = (35 + 9 + 30 + 5 + 0 + 4 + 2 + 9 + 48 + 6 + 0 + 9 + 10 + 15 + 0 + 0 + 2) = 184
184 usd11 = 16 + 8/11
SIGMA (AI x WI) (mod 11) = 8

Then, based on the calculation result, find the corresponding verification code from the following table. X indicates that the result is 10:

SIGMA (AI x WI) (mod 11) 0 1 2 3 4 5 6 7 8 9 10
Verification Code character value aI1 0x9 8 7 6 5 4 3 2

According to the above method, it is found that the verification code of 8 is 4, so the identity of the person is
The number should be 513101198201130014.

/+ ============================================== ========================================================== ======================================= */
If ll_identity_no_len = 18 then // test the 18-bit verification code

Long AI = 0
String code, old_id
Int J
Old_id = trim (sle_1.text)

For J = 17 to 1 step-1
Ai = ai + (long (mid (old_id, J, 1) * (mod (2 ^ (18)-j), 11 ))
Next

Choose case Mod (AI, 11)
Case 0
Code = '1'
Case 1
Code = '0'
Case 2
Code = 'X'
Case else
Code = string (12)-Mod (AI, 11 ))
End choose

If right (as_identity, 1) <> code then
MessageBox ("system prompt", "the last digit is incorrect", stopsign !, OK !)
Return false
End if

End if

Return true

Trackback: http://tb.donews.net/TrackBack.aspx? Postid = 416176

 

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.