2.2.1 • Published 1 year ago

validid v2.2.1

Weekly downloads
414
License
MIT
Repository
github
Last release
1 year ago

Validid: Validate ID Card Number

Validid is a Javascript library to validate ID Card numbers of China, Taiwan, Hong Kong and South Korea. Available in npm and bower.

(Validid 是一個 Javascript 程式庫,用作校驗身份證號碼是否基本正確,現時支援中國丶台灣丶香港和韓國 :)

What It Excels

  • Deeper validation, more than checksum, e.g. gender, excluding characters in real practice.
  • Same code base and usage in front-end and back-end.
  • Validate multiple card types, or selectively import individual modules (Welcome requests for more!).
  • Supports IE.

Quick Examples

Simply provide cardType and ID. validid will return true or false:

// China ID card
validid.cnid('120103198806018241'); // return true

// Taiwan ID card
validid.twid('A123456789'); // return true

// Taiwan Resident Certificate 2021
validid.twrc('A800000014'); // return true
// while validate old format
validid.twrc('AB12345677'); // return true
// old format "only" (not recommended, though)
validid.twrcLegacy('A800000014'); // return false
validid.twrcLegacy('AB12345677'); // return true

// Hong Kong ID card: supports two leading letters
validid.hkid('AB9876543'); // return true

// Korea ID card
validid.krid('781030-5668081'); // return true

Currently support:

cardTypeCountry / PlaceName(s) of Card
cnidChinaChina ID card, Resident Identity Card of the People's Republic of China (PRC), 中华人民共和国居民身份证
hkidHong KongHong Kong ID card, 香港身份證
twidTaiwanTaiwan ID card, National Identification Card of the Republic of China, 中華民國國民身分證, 臺灣身分證
twrcTaiwanTaiwan Resident Certificate (Uniform ID Numbers), 中華民國居留證 (統一證號)
kridSouth KoreaSouth Korea ID card, Resident Registration Number (RRN), 주민등록번호, 住民登錄番號

Install and Usage

Validid can be installed via npm, Bower, or run in browser directly. You can also consume it using your favorite bundling tools.

npm

npm install validid

Require in node.js:

var validid = require('validid'); // point to validid.umd.min.js
validid.cnid('120103198806018241'); // return true

Or, import module(s) in Node 13+:

// import the whole validid object
import validid from 'validid/esm/index.mjs';
// import individual module function
import krid from 'validid/esm/krid.mjs';
// import utility in your project
import normalize from 'validid/esm/utils/normalize.mjs';

validid.krid('781030-5668081'); // return true
krid('781030-5668081'); // return true
normalize('g123456(a)'); // return 'G123456A'

Bundling Tools :new:

In v2, validid bundles ESM and UMD formats. You can make use of them in bundling tools such as Webpack, Rollup and more. Please see <package.json>:

{
  "//": "...",
  "main": "bundles/validid.umd.min.js",
  "module": "bundles/validid.esm.mjs",
  "//": "..."
}

In most cases, you may import validid by resolving "module" rather than "main".

Bower

You can download and easily update validid via Bower package manager. In Bower, both bundled UMD <validid.umd.js> and minified UMD <validid.umd.min.js> are provided.

bower install validid

And it is ready to serve in front-end environment:

<html>
	<head>
		<script src="bower_components/validid/bundles/validid.umd.js"></script>
		<script src="test.js"></script>
	</head>
</html>
/* In test.js */
console.log(validid.cnid('120103198806018241')); // true

Direct Download

Nothing can stop you. Download the file validid.umd.js and refer it in your html file:

<html>
	<head>
		<script src="validid.umd.js"></script>
	</head>
</html>

And you are ready to go:

console.log(validid.cnid('120103198806018241')); // true

Help Me Out!

This repo is in stable and ready for you, while here are some aspects need your help:

  • Bugs and new policy that may need an update. However, please do not expose any real ID.
  • Grammar and writing, including code comments.
  • Open an issue if you want more than simple true/false validation.
  • I'm not sure why developers need an ID generator. Please tell me your need.
  • Any suggestion you want to make.

Copyright and License

Copyright (c) Edditoria. All rights reserved. Code released under the MIT License. Docs released under Creative Commons.

As human-readable summary (but not a substitute for the license):

You can use it, share it, modify the code and distribute your work for private and commercial uses. If you like, please share your work with me. :pizza:

2.2.1

1 year ago

2.2.0

3 years ago

2.1.0

3 years ago

2.0.0

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

5 years ago

1.0.0

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago