thai-id-validator
v1.1.3
Published
Thai Citizen ID validator with zero dependencies
Downloads
696
Maintainers
Readme
Thai Citizen ID Validator
A simpler way to validate Thai Citizen Card ID. 🇹🇭
Further Plans
- Go Language Implementation Example
- Thai Passport Number Validation
Read the article
Building Thai Citizen ID Input Validation with WCAG Standard
Installation
$ npm install thai-id-validator
# or
$ yarn add thai-id-validator
Data Type
| Input | Output | | ------ | :-----: | | String | boolean |
Usage
Javascipt ES5
Just import script with commonjs
var validateThaiID = require('thai-id-validator') // for ES5
var result = validateThaiID(‘1101700207030’);
console.log(result);
// return true
Javascript ES6 Module
In Javascript file, you can use import, export modules
'use strict';
import validateThaiID from 'thai-id-validator';
let result = validateThaiID(‘1101700207030’);
console.log(result);
// return true
Test
To run all test cases run the following command
npm run test
You can edit validator.test.js too add your custom test case.
| Test Cases | Result | | ------------- | :----: | | 1112034563562 | ✅ | | 1101700230705 | ❌ | | 110170023073 | ❌ | | 11017002070d3 | ❌ | | rytege54fsfsf | ❌ | | 0 | ❌ | | '-' | ❌ | | '' | ❌ | | null | ❌ | | 'blablabla' | ❌ |
(Tested with Vitest)
Test Result Screenshot
How to upload test coverage report to codacy
export CODACY_PROJECT_TOKEN=xxxxxxxxx
pnpm run coverage
bash <(curl -Ls https://coverage.codacy.com/get.sh)
Compatibility
Supports all major browsers and IE11+
| Edge | Firefox | Chrome | Safari | Chrome | Opera | | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ✅ | ✅ | ✅ | ✅ | ✅ |
Issues
If you found any 🐞 or feedback, please report the issue here
Contribution
👩🏻💻 Contribute are always welcome.
License
Code with love 🦉