JS ID number Verification-support for the new ID card with X

Source: Internet
Author: User
Tags getdate

JS ID number Verification-support for the new ID card with X

function Isidcardno (SID) {
var acity={11: "Beijing", 12: "Tianjin", 13: "Hebei", 14: "Shanxi", 15: "Inner Mongolia", 21: "Liaoning", 22: "Jilin", 23: "Heilongjiang", 31: "Shanghai", 32: "Jiangsu", 33: "Zhejiang", 34: "Anhui", 35 : "Fujian", 36: "Jiangxi", 37: "Shandong", 41: "Henan", 42: "Hubei", 43: "Hunan", 44: "Guangdong", 45: "Guangxi", 46: "Hainan", 50: "Chongqing", 51: "Sichuan", 52: "Guizhou", 53: "Yunnan", 54: "Tibet", 61: "Shaanxi", 62: "Gansu", 63: "Qinghai", 64: "Ningxia", 65: "Xinjiang", 71: "Taiwan", 81: "Hong Kong", 82: "Macao", 91: "Foreign"};
var isum=0;
var info= "";
if (!/^d{17} (d|x) $/i.test (SID) &&!/^d{15}$/i.test (SID)) return false;
Sid=sid.replace (/x$/i, "a");
if (Acity[parseint (Sid.substr (0,2))]==null) return false;

Switch (sid.length) {
Case 15:
Sbirthday= "+sid.substr" (6,2) + "-" +number (Sid.substr (8,2)) + "-" +number (Sid.substr (10,2));
var d=new date (Sbirthday.replace (/-/g, "/"));
if (sbirthday!= (d.getfullyear () + "-" + (D.getmonth () +1) + "-" + d.getdate ()) return false;
Break
Case 18:
Sbirthday=sid.substr (6,4) + "-" +number (Sid.substr (10,2)) + "-" +number (Sid.substr (12,2));
var d=new date (Sbirthday.replace (/-/g, "/"));
if (sbirthday!= (d.getfullyear () + "-" + (D.getmonth () +1) + "-" + d.getdate ()) return false;
for (var i = 17;i>=0;i-) Isum + = (Math.pow (2,i)%) * parseint (Sid.charat (17-i), 11);
if (isum%11!=1) return false;
Break
}
return true;
}
Call method

Simple Authentication ID
function C_sfz (v) {
return Isidcardno (v)? True:false;
Return/^ (?:d {15}|d{18}|d{17}[a-za-z]) $/.test (v);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.