Coder Social home page Coder Social logo

chinese-idcard-checker's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

chinese-idcard-checker's Issues

15位身份证号码处理

/**
* 身份证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('身份证格式错误!');
}
};

safari 下获取生日失败

原因在于这段

getBirthDate(idCardNum: string): Date | null {
if (this.validate(idCardNum)) {
const birthDate = idCardNum.substring(6, 14);
const year = this.getYear(birthDate);
const month = this.getMonth(birthDate);
const date = this.getDay(birthDate);
return new Date(`${year}-${month}-${date}`);
}
return null;
}

const date = this.getDay(dateString);
const fullDate = new Date(`${year}-${month}-${date}`);
if (fullDate && fullDate.getMonth() === month - 1) {
return true;

return new Date(`${year}-${month}-${date}`);

如果生日是单为数

比如 2000-1-1,在 safari 下 new Date('2000-1-1') 会抛出异常

把 0 补齐就没问题 new Date('2000-01-01')

截屏2020-08-18 15 47 21

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.