Coder Social home page Coder Social logo

chinese-idcard-checker's Introduction

chinese-idcard-checker

npm Build Status Coverage Status

🇨🇳中华人民共和国居民身份证验证器

安装

yarn add chinese-idcard-checker

如果使用npm则执行 npm install chinese-idcard-checker --save 安装

用法

import IDCardChecker from 'chinese-idcard-checker';
// or 
// const IDCardChecker = require('chinese-idcard-checker'); 

// 验证身份证有效性
IDCardChecker.validate(idCardNum); // true or false

// 获取省份
IDCardChecker.getProvince(idCardNum); // '北京市'

// 获取出生日期
IDCardChecker.getBirthDate(idCardNum);  // new Date('1949-10-1')

// 获取性别
IDCardChecker.getGender(idCardNum); // '男','女'

// 返回正则表达式常量
const pattern = IDCardChecker.pattern(); // /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
if(pattern.test(idCardNum)){
  // ...
}

API

idCardChecker.pattern() ⇒ RegExp

返回正则表达式

Returns: RegExp - /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/

idCardChecker.validate(idCardNum) ⇒ boolean

验证身份证有效性

Param Type Description
idCardNum string 身份证号码

idCardChecker.getProvince(idCardNum) ⇒ string | null

获取省份

Returns: string | null - 身份证号码

Param Type Description
idCardNum string 身份证号码

idCardChecker.getBirthDate(idCardNum) ⇒ Date | null

获取出生日期

Returns: Date | null - 出生日期

Param Type Description
idCardNum string 身份证号码

idCardChecker.getGender(idCardNum) ⇒ string | null

获取性别

Returns: string | null - '男','女'

Param Type Description
idCardNum string 身份证号码

LICENSE

MIT License

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.