Function checkidcard (strnumber)
{
// ID card number format Function
// The citizenship number is a feature combination code,
// The Order is from left to right: six-digit address code, eight-digit birth date code, three-digit sequence code, and one-digit verification code.
// Determine the length of the ID card number
If (strnumber. Length <15 | strnumber. Length = 16 | strnumber. Length = 17 | strnumber. length> 18)
{
Alert ("the length of the ID card number is incorrect. Please enter it again! ");
Return false;
}
// The last digit of the ID card number may be x. x of an elderly person over 100 years old. It can also represent the Arabic numerals 10.
// Eliminate the last digit for digital format testing. The last digit has the last digit.
VaR AI;
If (strnumber. Length = 18)
{
Ai = strnumber. substring (0, 17 );
}
Else
{
Ai = strnumber. substring (0, 6) + "19" + strnumber. substring (6, 9 );
}
// Call the number judgment function isnumeric ()
If (isnumeric (AI) = false)
{
Alert ("the number string of the ID card number is incorrect. Please enter it again! ");
Return false;
}
VaR stryear, strmonth, strday, strbirthday;
Stryear = parseint (AI. substr (6, 4 ));
Strmonth = parseint (AI. substr (10, 2 ));
Strday = parseint (AI. substr (12, 2 ));
// Call the date judgment function isvaliddate ()
If (isvaliddate (stryear, strmonth, strday) = false)
{
Alert ("ID card number" + AI + "Date Format year" + stryear + "month" + strmonth + "day" + strday + "Incorrect. Please enter it again! ");
Return false;
}
VaR arrverifycode = new array ("1", "0", "X", "9", "8", "7", "6", "5 ", "4", "3", "2 ");
VaR Wi = new array (, 2 );
VaR K, totalmulaiwi = 0;
For (k = 0; k <17; k ++)
{
Totalmulaiwi = totalmulaiwi + parseint (AI. substr (k, 1) * WI [k];
}
// Alert ("the last digit of the ID card number is:" + totalmulaiwi );
VaR modvalue = totalmulaiwi % 11;
VaR strverifycode = arrverifycode [modvalue];
Ai = ai + strverifycode;
// Alert ("ID card number" + strnumber + "is consistent with the correct number" + AI +! ");
If (strnumber. Length = 18) & (strnumber! = Ai ))
{
Alert ("ID card number" + strnumber + "is different from the correct number" + AI + ". Please enter it again! ");
Return false;
}
Return true;
}
// Number judgment function isnumeric ()
Function isnumeric (onum)
{
If (! Onum) return false;
VaR STRP =/^/d + (/./d + )? $ /;
If (! STRP. Test (onum) return false;
Try {
If (parsefloat (onum )! = Onum) return false;
}
Catch (Ex)
{
Return false;
}
Return true;
}
// Isvalidyear ()
Function isvalidyear (psyear)
{
VaR syear = new string (psyear );
If (psyear = NULL)
{
Alert ("the year in the birth date of the ID card number is null. Please enter it again! ");
Return false;
}
If (isnan (psyear) = true)
{
Alert ("the year in the date of birth must be a number. Please enter a new one! ");
Return false;
}
If (syear = "")
{
Alert ("the year in the birth date of the ID card number is blank. Please enter it again! ");
Return true;
}
If (syear. Match (/[^ 0-9]/g )! = NULL)
{
Alert ("the year in the date of birth must be a number between 0 and 9. Please enter it again! ");
Return false;
}
VaR nyear = parseint (syear, 10 );
If (nyear <0) | (9999 <nyear ))
{
Alert (nyear + "ID card number in the date of birth must be a normal positive integer, please fill in again! ");
Return false;
}
Return true;
}
// Valid month judgment function isvalidmonth ()
Function isvalidmonth (psmonth)
{
VaR smonth = new string (psmonth );
If (psmonth = NULL)
{
Return false;
}
If (isnan (psmonth) = true)
{
Return false;
}
If (smonth = "")
{
Return true;
}
If (smonth. Match (/[^ 0-9]/g )! = NULL)
{
Return false;
}
VaR nmonth = parseint (smonth, 10 );
If (nmonth <0) | (12 <nmonth ))
{
Return false;
}
Return true;
}
// Valid day judgment function isvalidday ()
Function isvalidday (psday)
{
VaR SDAY = new string (psday );
If (psday = NULL)
{
Return false;
}
If (isnan (psday) = true)
{
Return false;
}
If (SDAY = "")
{
Return true;
}
If (SDAY. Match (/[^ 0-9]/g )! = NULL)
{
Return false;
}
VaR nday = parseint (psday, 10 );
If (nday <0) | (31 <nday ))
{
Return false;
}
Return true;
}
// Effective date judgment function isvaliddate ()
Function isvaliddate (psyear, psmonth, psday)
{
If (psyear = NULL | psmonth = NULL | psday = NULL)
{
Return false;
}
VaR syear = new string (psyear );
VaR smonth = new string (psmonth );
VaR SDAY = new string (psday );
If (isvalidyear (syear) = false)
{
Return false;
}
If (isvalidmonth (smonth) = false)
{
Return false;
}
If (isvalidday (SDAY) = false)
{
Return false;
}
VaR nyear = parseint (syear, 10 );
VaR nmonth = parseint (smonth, 10 );
VaR nday = parseint (SDAY, 10 );
If (syear = "" & smonth = "" & SDAY = "")
{
Return true;
}
If (syear = "" | smonth = "" | SDAY = "")
{
Return false;
}
If (nmonth <1 | 12 <nmonth)
{
Return false;
}
If (nday <1 | 31 <nday)
{
Return false;
}
If (nmonth = 2)
{
If (nyear % 400 = 0) | (nyear % 4 = 0) & (nyear % 100! = 0 ))
{
If (nday <1) | (nday> 29 ))
{
Return false;
}
}
Else
{
If (nday <1) | (nday> 28 ))
{
Return false;
}
}
}
Else if (nmonth = 1) |
(Nmonth = 3) |
(Nmonth = 5) |
(Nmonth = 7) |
(Nmonth = 8) |
(Nmonth = 10) |
(Nmonth = 12 ))
{
If (nday <1) | (31 <nday ))
{
Return false;
}
}
Else
{
If (nday <1) | (30 <nday ))
{
Return false;
}
}
Return true;
}