js前端身份證完美驗證

2021-09-02 10:54:04 字數 1838 閱讀 9299

ar vcity=;

checkcard = function()

//校驗長度,型別

if(iscardno(card) === false)

//檢查省份

if(checkprovince(card) === false)

//校驗生日

if(checkbirthday(card) === false)

//檢驗位的檢測

if(checkparity(card) === false)

alert('ok');

return true;

}; //檢查號碼是否符合規範,包括長度,型別

iscardno = function(card)

$)|(^\d(\d|x)$)/;

if(reg.test(card) === false)

return true;

}; //取身份證前兩位,校驗省份

checkprovince = function(card)

return true;

}; //檢查生日是否正確

checkbirthday = function(card)

)(\d)(\d)(\d)(\d)$/;

var arr_data = card.match(re_fifteen);

var year = arr_data[2];

var month = arr_data[3];

var day = arr_data[4];

var birthday = new date('19'+year+'/'+month+'/'+day);

return verifybirthday('19'+year,month,day,birthday);

} //身份證18位時,次序為省(3位)市(3位)年(4位)月(2位)日(2位)校驗位(4位),校驗位末尾可能為x

if(len == '18')

)(\d)(\d)(\d)(\d)([0-9]|x)$/;

var arr_data = card.match(re_eighteen);

var year = arr_data[2];

var month = arr_data[3];

var day = arr_data[4];

var birthday = new date(year+'/'+month+'/'+day);

return verifybirthday(year,month,day,birthday);

} return false;

}; //校驗日期

verifybirthday = function(year,month,day,birthday)

return false;

} return false;

}; //校驗位的檢測

checkparity = function(card)

valnum = arrch[cardtemp % 11];

if (valnum == card.substr(17, 1))

return false;

} return false;

}; //15位轉18位身份證號

changefivteentoeighteen = function(card)

card += arrch[cardtemp % 11];

return card;

} return card;

}; test.html

html** 收藏**

請輸入身份證號碼:

超實用的php驗證身份證和js驗證身份證的方法

js驗證身份證的方法 function validateidcard idcard 0 d 1 0 2 0 1 2 d 3 0 1 d 1 9 d 1 9 d 0 d 1 0 2 0 1 2 d 3 0 1 d d xx 如果通過該驗證,說明身份證格式正確,但準確性還需計算 if regidcard...

js 身份證號驗證

function iscardid sid var isum 0 var info if d d x i.test sid return 身份證長度或格式錯誤 sid sid.replace x i,a if acity parseint sid.substr 0,2 null return 身份證...

PHP驗證身份證

原作者有個錯的地方改了轉過來 document 檢查符合 gb11643 1999 標準的身份證號碼的正確性 file gb11643 1999.func.php fri mar 28 09 42 41 cst 2008 zxing updated fri mar 28 09 42 41 cst 2...