# Asp id card number verification function

Source: Internet
Author: User

ID card number verification function
Function checkidcard (S, d, g)
{
If (! S) return false;
D = new date (d );
If (! D. gettime () return false;

VaR T, R;

T = "" + D. getfullyear () + dblnum (D. getmonth () + 1) + dblnum (D. getdate ());

If (G = NULL | isnan (G) return false;
G = parseint (g) % 2;

Switch (S. length)
{
Case 8:
If (new date ()> D. setfullyear (D. getfullyear () + 19) return false;
R =/^ [/d] {8} \$ /;
If (! R. test (s) return false;
If (s! = T) return false;

Break;
Case 15:
R =/^ [/d] {15} \$ /;
If (! R. test (s) return false;
If (S. substr (6, 6 )! = T. substr (2) return false;
If (parseint (S. charat (14) % 2! = G) return false;

Break;
Case 18:
R =/^ (? : [/D] {18} | [/d] {17} X) \$/I;
If (! R. test (s) return false;
If (S. substr (6, 8 )! = T) return false;
If (parseint (S. charat (16) % 2! = G) return false;

VaR n = 0;
VaR W = new array (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); // Weighting Factor
VaR c = new array ("1", "0", "X", "9", "8", "7", "6", "5 ", "4", "3", "2"); // Verification Code

For (VAR I = 0; I <17; I ++)
{
N + = parseint (S. charat (I) * W [I];
}

If (S. charat (17). touppercase ()! = C [n % 11]) return false;

Break;
Default:
Return false;
}

Return true;
}

Function dblnum (N)
{
Return parseint (n) <10? "0" + N: N;
}

// Var SSS = "422324860305482 ";
// Response. Write (checkidcard (SSS, "03/05/1986", 0 ));

Related Keywords:
Related Article

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.