Home >Web Front-end >JS Tutorial >JavaScript Date of Birth and ID Card Judgment_Time and Date
if(document.form1.csrq.value==""){
alert("Please fill in your date of birth!");
document.form1.csrq.focus();
return false;
}
if(document.form1.csrq.value==""){
alert("Please fill in your date of birth!");
document.form1.csrq.focus();
return false;
}else{
if(document.form1.csrq.value.length!=8){
alert("Date of birth 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 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("Date of birth is inconsistent with ID 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"; //Capital letters
badChar = "abcdefghijklmnopqrstuvwxyz"; / /Lowercase letters
badChar = "0123456789"; //Numbers
badChar = " " " ";//Half-width and full-width spaces
badChar = "`~!@#$%^&()-_ = ]\|:;"\'?/";//Special symbols
var c;
//for(var i=0;i
if(badChar.indexOf(c) != -1){ //If the current character is in A matching character was found in badChar, indicating that 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 it is an officer number, please enter it completely. For example: a military officer's ID number is Zhengzi No. 123456; if it is an ID number, please check your The number of digits entered must be 15 or 18 digits. ");
return false;
}
var a = num.match(re);
if (a != 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(" The date of birth in the entered ID number " a[0] " is incorrect! "); return false;}
}
return true;
}