🇹🇭 Thai Citizen ID validator with zero dependencies
Thai Citizen ID Validator
A simpler way to validate Thai Citizen Card ID. 🇹🇭
Minimum Node.js Version ⚠️
This package requires Node.js version 16 or later.
Future Roadmap
- Go Language Implementation Example
- .NET Language Implementation Example
- Thai Passport Number Validation
Read the article
Building Thai Citizen ID Input Validation with WCAG Standard
Installation
Works with npm, jsr, yarn, pnpm, bun or deno
$ npm install thai-id-validator # or $ yarn add thai-id-validator # or $ pnpm add thai-id-validator # or $ bun add thai-id-validator # or $ pnpm dlx jsr add @jukbot/thai-id-validator # or $ deno add jsr:@luca/flag
Data Type
| Input | Output |
|---|---|
| String | boolean |
Usage
Javascript / Typescript
In Javascript, Typescript file, you can use import, export modules
import isValidThaiID from 'thai-id-validator'; let result = isValidThaiID(‘1101700207030’); console.log(result); // true
Test
To run all test cases run the following command
bun run test
You can edit validator.test.js too add your custom test case.
| Test Cases | Result |
|---|---|
| '1112034563562' | ✅ |
| '0113200420331' | ✅ |
| '1101700230705' | ❌ |
| '110170023073' | ❌ |
| '11017002070d3' | ❌ |
| 'rytege54fsfsf' | ❌ |
| 0 | ❌ |
| '-' | ❌ |
| '' | ❌ |
| null | ❌ |
| undefined | ❌ |
| 'blablabla' | ❌ |
(Tested with Bun)
Test Result Screenshot
How to upload test coverage report to codacy
export CODACY_PROJECT_TOKEN=xxxxxxxxx bun run coverage bash <(curl -Ls https://coverage.codacy.com/get.sh)
Compatibility
Tested on all modern browsers ✅
Issues
If you found any 🐞 or feedback, please report the issue here
Contribution
👩🏻💻 Contribute are always welcome.
License
Code with love 🦉
Add Package
deno add jsr:@jukbot/thai-id-validator
Import symbol
import * as thai_id_validator from "@jukbot/thai-id-validator";
Import directly with a jsr specifier
import * as thai_id_validator from "jsr:@jukbot/thai-id-validator";
Add Package
pnpm i jsr:@jukbot/thai-id-validator
pnpm dlx jsr add @jukbot/thai-id-validator
Import symbol
import * as thai_id_validator from "@jukbot/thai-id-validator";
Add Package
yarn add jsr:@jukbot/thai-id-validator
yarn dlx jsr add @jukbot/thai-id-validator
Import symbol
import * as thai_id_validator from "@jukbot/thai-id-validator";
Add Package
vlt install jsr:@jukbot/thai-id-validator
Import symbol
import * as thai_id_validator from "@jukbot/thai-id-validator";
Add Package
npx jsr add @jukbot/thai-id-validator
Import symbol
import * as thai_id_validator from "@jukbot/thai-id-validator";
Add Package
bunx jsr add @jukbot/thai-id-validator
Import symbol
import * as thai_id_validator from "@jukbot/thai-id-validator";