本文介绍了如何验证身份证号码与出生日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在web表单中验证出生日期的第6个身份证号码.plz help
how do you validate 1st 6 id number with date of birth in web form.plz help
推荐答案
string id = "021345052";
id = id.Substring(0, 6);
问候,
Eduard
Regards,
Eduard
function ValidateRSAIDNo(id) {
try {
if (id.length != 13) return false;
var y1o = id.substring(0, 1)
var y2e = id.substring(1, 2)
var m1o = id.substring(2, 3)
var m2e = id.substring(3, 4)
var d1o = id.substring(4, 5)
var d2e = id.substring(5, 6)
var go = id.substring(6, 7)
var s1e = id.substring(7, 8)
var s2o = id.substring(8, 9)
var s3e = id.substring(9, 10)
var co = id.substring(10, 11)
var ae = id.substring(11, 12)
var z = id.substring(12, 13)
var A = 0;
A = parseInt(A) + parseInt(y1o) + parseInt(m1o) + parseInt(d1o) + parseInt(go) + parseInt(s2o) + parseInt(co);
var B1 = y2e + m2e + d2e + s1e + s3e + ae;
var B2 = B1 * 2;
var i = 0;
var B3 = 0;
var B2string = B2.toString();
while (B2string.length > i) {
var x = B2string.substring(i, i + 1);
B3 = B3 + parseInt(x);
i = i + 1;
}
var C = A + B3;
var Cstring = C.toString();
var secNo = Cstring.substring(1, 2);
var D = 10 - parseInt(secNo);
while (D >= 10) D = D - 10;
if (D == z) {
//test for valid date in 1900
var valid = true;
var bd = new Date('19' + y1o + y2e, parseInt(m1o + m2e) - 1, d1o + d2e);
if ((bd == 'NaN') | (bd == 'Invalid Date')) valid = false;
else if (bd.getFullYear() != parseInt('19' + y1o + y2e)) valid = false;
else if (bd.getMonth() + 1 != parseInt(m1o + m2e)) valid = false;
else if (bd.getDate() != parseInt(d1o + d2e)) valid = false;
//if invalid test again in 2000
valid = true;
bd = new Date('20' + y1o + y2e, parseInt(m1o + m2e) - 1, d1o + d2e);
if ((bd == 'NaN') | (bd == 'Invalid Date')) valid = false;
else if (bd.getFullYear() != parseInt('20' + y1o + y2e)) valid = false;
else if (bd.getMonth() + 1 != parseInt(m1o + m2e)) valid = false;
else if (bd.getDate() != parseInt(d1o + d2e)) valid = false;
//return result
return valid;
}
else {
return false;
}
}
catch (e) {
return false;
}
}
这篇关于如何验证身份证号码与出生日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!