A Javascript library to validate ID card numbers of Hong Kong, Taiwan, South Korea and China.
MIT License
Validid is a Javascript library to validate ID card number of Hong Kong, Taiwan, South Korea and China. Available in npm and bower.
(Validid 是一個 Javascript 程式庫,用作校驗身份證號碼是否基本正確,現時支援香港丶台灣丶韓國和中國 :)
Most likely you would import function starting with a word "validate":
// Hong Kong ID card (Supports two leading letters):
import { validateHkid } from 'validid/hkid';
validateHkid('AB987654(3)'); // returns { id: 'AB9876543', ok: true, ... }
// Taiwan ID card (including National Identification Card and Resident Certificate):
import { validateTwid, identifyTwidType, identifyTwrcVersion } from 'validid/twid';
validateTwid('A123456789'); // returns { ok: true, ... }
// Some services still need to identify NIC and RC:
identifyTwidType('A123456789'); // returns "NIC"
identifyTwidType('A800000014'); // returns "RC"
// And even to identify old and new RC:
identifyTwrcVersion('A800000014'); // returns "RC_2021"
identifyTwrcVersion('AB12345677'); // returns "RC_LEGACY"
// Korea ID card:
import { validateKrid } from 'validid/krid';
validateKrid('781030-5668081'); // returns { id: "7810305668081", ok: true, ... }
// No checksum is required according to latest system:
validateKrid('7810305668082'); // returns { id: "7810305668082", ok: true, ... }
// China ID card:
import { validateCnid } from 'validid/cnid';
validateCnid('120103198806018241'); // returns { ok: true, ... }
Currently support:
Module | Country / Place | Name(s) of Card |
---|---|---|
hkid | Hong Kong | Hong Kong ID card, 香港身份證 |
twid | Taiwan | National Identification Card of the Republic of China, 中華民國國民身分證, 臺灣身分證 |
twid | Taiwan | Resident Certificate (Uniform ID Numbers), 中華民國居留證 (統一證號) |
krid | South Korea | South Korea ID card, Resident Registration Number (RRN), 주민등록번호, 住民登錄番號 |
cnid | China | China ID card, Resident Identity Card of the People's Republic of China (PRC), 中华人民共和国居民身份证 |
There are vary of exported utilities in this package. They might help your UI.
Validid can be installed via npm, Bower, or run in browser directly. You can also consume it using your favorite bundling tools.
npm install validid
Import ES module that you need:
import { validateTwid } from 'validid/twid';
Require in old fashion. No module. All-in-one named export:
const { validateTwid } = require('validid'); // point to validid.umd.js
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:
<html>
<body>
<script src="bower_components/validid/bundles/validid.umd.js"></script>
<script src="your-scripts.js"></script>
</body>
</html>
/* In your-scripts.js */
const result = validid.validateHkid('A9876543');
console.log(result.ok); // false
console.log(result.status.text) // "INVALID_CHECKSUM"
Nothing can stop you. Download the UMD file, then use the global name validid
in your page:
<html>
<body>
<script src="validid.umd.js"></script>
<script>
const result = validid.validateHkid('A9876543');
console.log(result.ok); // false
console.log(result.status.text) // "INVALID_CHECKSUM"
</script>
</body>
</html>
Please check out release page on Github.
This repo is in stable and ready for you, while here are some aspects need your help:
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. 🍕