If (document. form1.csrq. value = ""){
Alert ("Enter the date of birth! ");
Document. form1.csrq. focus ();
Return false;
}
If (document. form1.csrq. value = ""){
Alert ("Enter the date of birth! ");
Document. form1.csrq. focus ();
Return false;
} Else {
If (document. form1.csrq. value. length! = 8 ){
Alert ("the birth date must be 8 digits! ");
Document. form1.csrq. focus ();
Return false;
}
If (document. form1.sfzh. value. length = 18 ){
Var sfzh = document. form1.sfzh. value;
If (document. form1.csrq. value! = Sfzh. substring (6, 14 )){
Alert ("the date of birth is inconsistent with the ID card number! ");
Document. form1.csrq. focus ();
Return false;
}
}
If (document. form1.sfzh. value. length = 15 ){
Var sfzh = document. form1.sfzh. value;
If (document. form1.csrq. value! = '19' + sfzh. substring (6, 12 )){
Alert ("the date of birth is inconsistent with the ID card number! ");
Document. form1.csrq. focus ();
Return false;
}
}
}
If (! IsIdCardNo (document. form1.sfzh. value )){
Document. form1.sfzh. focus ();
Return false;
}
Function isNN (num ){
Var badChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // uppercase letter
BadChar + = "abcdefghijklmnopqrstuvwxyz"; // lowercase letter
BadChar + = "0123456789"; // number
BadChar + = "" + ""; // halfwidth and fullwidth Spaces
BadChar + = "'~! @ # $ % ^ & ()-_ = +] \\| :;\" \\' <,>? /"; // Special symbol
Var c;
// For (var I = 0; I <name. length; I ++) {// judge the characters in name in sequence
C = num. charAt (0); // extracts the 1st characters in num.
If (badChar. indexOf (c )! =-1) {// if the current character matches a character in badChar, it is not a Chinese character
Return false;
} Else {
Return true;
}
}
Function isIdCardNo (num)
{
// If (isNaN (num) {alert ("the input is not a number! "); Return false ;}
Var len = num. length, re;
If (len = 15 ){
Re = new RegExp (/^ (\ d {6 })()? (\ D {2}) (\ d {2}) (\ d {2}) (\ d {3}) $ /);
} Else if (len = 18 ){
Re = new RegExp (/^ (\ d {6 })()? (\ D {4}) (\ d {2}) (\ d {2}) (\ d {3}) (\ d) $ /);
} Else if (isNN (num )){
Return true;
} Else {
Alert ("if the officer ID is complete, for example, a military officer ID is Zheng Zi 123,456th. If it is an ID card number, check the number of digits you entered. It must be 15 or 18 digits. ");
Return false;
}
Var a = num. match (re );
If (! = Null)
{
If (len = 15)
{
Var D = new Date ("19" + a [3] + "/" + a [4] + "/" + a [5]);
Var B = D. getYear () = a [3] & (D. getMonth () + 1) = a [4] & D. getDate () = a [5];
}
If (len = 18)
{
Var D = new Date (a [3] + "/" + a [4] + "/" + a [5]);
Var B = D. getFullYear () = a [3] & (D. getMonth () + 1) = a [4] & D. getDate () = a [5];
}
If (! B) {alert ("entered ID card number" + a [0] + "contains incorrect birthdate! "); Return false ;}
}
Return true;
}