jq ID number verification (detailed)

//Check whether the ID card is valid (new)
function checkCardNumber(text, callback){


checkAge = true;
var number = text;
if (number == null || number == "") {
return callback("Please enter true Valid ID number");
// eleCtrlShow($('#realNum'),'.comm','activeErr','Please enter a real and valid ID number');
// return false;
}
if (! cc_checkPersonidRegister(text)) {
return callback("The format is incorrect, please re-enter");
// eleCtrlShow($('#realNum'),'.comm','activeErr', 'The format is incorrect, please re-enter' );
// return false;
}
eleCtrlHide($('#realNum'),'.comm','activeErr');
return true;
}


function cc_checkPersonidRegister(text) {
$(this).val($.trim(text));
var personid = text;


if (personid.length == 15 || personid.length == 18) {


if (checkIdCard(personid)) {
if (!checkDate()) {
return false;
} else {
return true;
}
} else {
return false;
}
} else {
return false;
}
}


// 检查身份证号码


function checkDate(y1, y2, y3) {
if (Number(y2) != 1 && Number(y2) != 3 && Number(y2) != 5
&& Number(y2) != 7 && Number(y2) != 8 && Number(y2) != 10
&& Number(y2) != 12) {
if (Number(y3) > 30) {
return false;
}
}
if (Number(y2) == 2) {
if (Number(y1) % 100 == 0) {
if (Number(y1) % 400 == 0) {
if (Number(y3) > 29) {
return false;
}
} else {
if (Number(y3) > 28) {
return false;
}
}
} else {
if ( Number(y1) % 4 == 0) {
if (Number(y3) > 29) {
return false;
}
} else {
if (Number(y3) > 28) {
return false;
}
}
}
}
return true;
}


/ / ID verification, real-name verification, rule 091223b
var checkAge = true;
function checkIdCard(personid) {
if (personid.length == 15 || personid.length == 18) {
// Check for special characters
if (personid .length == 15) {
for (i = 0; i < personid.length; i++) {
if (isNaN(parseInt(personid.charAt(i), 10))) {
alert('ID number contains illegal character 1');
// identity ID contains illegal characters
return false;
}
}
} else {
for (i = 0; i < personid.length - 1; i++) {
if (isNaN(parseInt(personid.charAt(i), 10))) {
alert ('The ID number contains illegal characters 2');
// The ID number contains illegal characters
return false;
}
}
var lastIDNum = personid.charAt(17);
if (isNaN(parseInt(lastIDNum, 10))
&& lastIDNum .toLowerCase() != 'x') {
alert('ID number contains illegal characters 3');
// ID number contains illegal characters
return false;
}
}


// Region
var area1 = personid.substr(0, 2);
var area2 = personid.substr(2, 2);
var area3 = personid.substr(4, 2);
if (area1 != "11" && area1 != "12" && area1 != "13" && area1 != "14"
&& area1 != "15" && area1 != "21" && area1 != "22"
&& area1 != "23" && area1 != "31" && area1 != "32"
&& area1 != "33" && area1 != "34" && area1 != "35"
&& area1 != "36" && area1 != "37" && area1 != "41"
&& area1 != "42" && area1 != "43" && area1 != "44"
&& area1 != "45" && area1 != "46" && area1 != "50"
&& area1 != "51" && area1 != "52" && area1 != "53"
&& area1 != "54" && area1 != "61" && area1 != "62"
&& area1 != "63" && area1 != "64" && area1 != "65" && area1 != "63" && area1 != "64" && area1 != "65" && area1 != "63" && area1 != "64" && area1 != "65"
font * color=red>The area code in the ID number is incorrect! </font>"; div_idcard.className = * "ico_false"; MsgShow.style.display=""; MsgShow.innerHTML="<font
















* color=black>身份证输入错误</font>"; PersonMark.value="0"; return false; }
*/


// 年月日
var yyyy = "";
var mm = "";
var dd = "";
var yy1 = "";
if (personid.length == 15) {
yy1 = "19";
yyyy = yy1 + personid.substr(6, 2);
mm = personid.substr(8, 2);
dd = personid.substr(10, 2);
} else if (personid.length == 18) {
yy1 = personid.substr(6, 2);
yyyy = personid.substr(6, 4);
mm = personid.substr(10, 2);
dd = personid.substr(12, 2);
}
var flag = true;
if (yy1 != "18" && yy1 != "19" && yy1 != "20") {
flag = false;
} else {
if (parseInt(mm, 10) < 1 || parseInt(mm, 10) > 12) {
flag = false;
} else {
if (parseInt(dd, 10) < 1 || parseInt(dd, 10) > 31) {
flag = false;
}
}
}
if (!flag) {
alert('ID number birth date is wrong');
// ID card number birth date is wrong
return false;
}


// Year, cannot be less than 1900
if (Number(yyyy ) < 1900) {
alert('year is less than 1900');
return false;
}


// var d=new
// Date(yyyy,mm,dd),year=d.getFullYear(),mon=d.getMonth() ,day=d.getDate(),now=new
// Date();
var year = parseInt(yyyy, 10), mon = parseInt(mm, 10), day = parseInt(
dd, 10), now = new Date ();


// check digit
if (personid.length == 18) {
var vcode = personid.substr(17, 1);
if (vcode == "X") {
vcode = "x";
}
var arrVerifyCode = new Array("1", "0", "x", "9", "8", "7", "6",
"5", "4", "3", "2");
var wi = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8,
4, 2);
var totalmulAiWi = 0;
for (var i = 0; i < 17; i++) {
var num = parseInt(personid.substr(i, 1), 10);
totalmulAiWi = totalmulAiWi + num * wi[i];
}
var modValue = totalmulAiWi % 11;
if (vcode != arrVerifyCode[modValue]) {
alert('身份证号码校验错误'); // Age } } return false;
// ID number verification error






if (year > now.getFullYear()) {
alert('birth date of ID card is out of range');
// birth date of ID card is out of range
return false;
} else if (year == now.getFullYear()) {
if ( mon > (now.getMonth() + 1)) {
alert('ID birth date is out of range');
// ID birth date is out of range
return false;
} else if (mon == (now.getMonth() + 1)) {
if (day >= now.getDate()) {
alert('ID birth date is out of range');
// ID birth date is out of range
return false;
}
}
}
var diffYear = now.getFullYear() - year;
var diffMonth = now.getMonth() + 1 - mon;
var diffDay = now.getDate() - day;
if (diffYear < 18 || diffYear === 18
&& (diffMonth < 0 || diffMonth === 0 && diffDay < 0)) {
alert('The registered ID card information is underage, the account will be included in the anti-addiction, and the income will decrease as the game time increases');
// The registered ID card information is underage, the account will be included in the anti-addiction, with the game The increase of time will reduce the income
checkAge = false;
return false;
}
alert('ID card input is correct');
//ID card input is correct
return true;


} else {
alert('ID card number is incorrect, please enter 15 digits or 18-digit ID number');
// The ID number is incorrect, please enter a 15-digit or 18-digit ID number and
return false;
}
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326439555&siteId=291194637