weihongyu12 / chinese-idcard-checker Goto Github PK
View Code? Open in Web Editor NEW**居民身份证验证
License: MIT License
**居民身份证验证
License: MIT License
/**
* 身份证15位18位互转
* @param {string} oldCard - 身份证号码
* @return 18或15位身份证号码
*/
IDCardChecker.prototype.getIDCard = function (oldCard) {
try {
if (oldCard.length == 18) {
var strZJHM = oldCard.substr(0, 6) + oldCard.substr(8, 9);
return strZJHM.toLocaleUpperCase();
}
else if (oldCard.length == 15) {
var w = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
var a = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"];
var strZJHM = oldCard.substr(0, 6) + "19" + oldCard.substr(6);
var v_Sum = 0;
for (var i = 0; i < strZJHM.length; i++) {
v_Sum = v_Sum + Number(strZJHM.substr(i, 1)) * w[i];
}
var ai = v_Sum % 11;
strZJHM = strZJHM + a[ai];
return strZJHM.toLocaleUpperCase();
}
else {
throw new Error('身份证格式错误!');
}
}
catch (e) {
throw new Error('身份证格式错误!');
}
};
原因在于这段
chinese-idcard-checker/src/IDCardChecker.ts
Lines 187 to 196 in e3e930d
chinese-idcard-checker/src/IDCardChecker.ts
Lines 77 to 80 in e3e930d
return new Date(`${year}-${month}-${date}`);
如果生日是单为数
比如 2000-1-1
,在 safari 下 new Date('2000-1-1')
会抛出异常
把 0 补齐就没问题 new Date('2000-01-01')
我们一些旧项目就可以直接引用使用,新项目可以使用这种的
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.