agentleFS
ntaffziintaffzii/Skill-Agents/skills/thai/thai-id-validate/SKILL.md

thai-id-validate

Skill4 starsChanged 2 months agoMITView on GitHub

Use this skill for any task validating a Thai national ID or tax ID checksum, normalizing a Thai phone number, or generating a PromptPay QR code payload. Trigger on "เลขบัตรประชาชน", "เลขประจำตัวผู้เสียภาษี", "checksum บัตรประชาชน", "PromptPay QR", "สร้าง QR พร้อมเพย์", "Thai national ID validate", "13 digit ID checksum". If the task only needs a regex length check with no checksum or QR generation, this skill is still the right one to load — a naive 13-digit regex is exactly the mistake this skill exists to prevent.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Run python3 validate.py for the self-test — includes a CRC-16/CCITT-FALSE reference check value ("123456789" → 0x29B1, the standard …

    line 70
  2. Very specific:

    Only mobile-number and national-ID proxy types are implemented.

    line 76
  3. Distinctive:

    All example IDs used in this skill's self-test are generated by the checksum function itself — never hardcode or commit a real person's …

    line 77

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Thai ID / Phone / PromptPay Validation

Overview

A Thai national ID (and tax ID, same 13-digit scheme) has a checksum digit, not just a fixed length — a model that validates with ^\d{13}$ alone will happily accept an ID that fails the real check. PromptPay QR codes are EMVCo TLV-encoded with a CRC-16 checksum; hand-rolling this without the exact tag structure and CRC algorithm produces a QR code that scanner apps reject. This skill supplies the real checksum algorithm, phone normalization, and a working EMVCo payload builder.

When to use

  • ตรวจเลขบัตรประชาชน/เลขผู้เสียภาษี 13 หลักว่า checksum ผ่านไหม
  • Normalizing a Thai phone number from mixed formats (081-234-5678, +66 81 234 5678, 66812345678) to a single canonical form
  • Generating a PromptPay QR payload string for a mobile number or national ID proxy, static or with a fixed amount

When NOT to use

  • The task needs to verify an ID belongs to a real, specific person — that requires a government lookup (DOPA), not a checksum; checksum only proves the number is well-formed, not that it is real or belongs to anyone in particular
  • The task needs an actual scannable QR image — this skill produces the payload string; rendering it as a QR code image needs a QR-encoding library (e.g. qrcode in Python), which is outside this skill's scope

Core knowledge

National ID / tax ID checksum (13 digits, weighted mod-11):

sum = Σ d[i] * (13 - i)   for i = 0..11  (first 12 digits)
check_digit = (11 - (sum % 11)) % 10

The 13th digit must equal check_digit. This is the same algorithm for a personal national ID and a juristic-person tax ID.

Phone normalization: canonical local form is 0 + 9 digits (10 digits total, e.g. 0812345678). International form drops the leading 0 and prefixes 66 (e.g. 66812345678 or +66 81 234 5678).

PromptPay QR payload (EMVCo QR Code for Payment Systems, Thai PromptPay profile): a flat TLV (tag-length-value) string:

TagMeaningValue
00Payload Format Indicator01
01Point of Initiation Method11 static (no amount) / 12 dynamic (fixed amount)
29Merchant Account Info (PromptPay)nested TLV: 00=GUID A000000677010111, 01=mobile proxy (0066 + 9-digit phone) or 02=13-digit national/tax ID proxy
53Transaction Currency764 (ISO 4217 numeric code for THB)
54Transaction AmountTHB amount, 2 decimals — only present on a dynamic QR
58Country CodeTH
63CRCCRC-16/CCITT-FALSE (poly 0x1021, init 0xFFFF, no reflect, xorout 0) of everything up to and including the 6304 tag+length prefix, appended as 4 uppercase hex digits

Each TLV entry is tag(2 chars) + length(2-digit decimal) + value.

Common mistakes

  1. Validating a Thai ID with only a ^\d{13}$ length regex — misses the checksum entirely, the most common "looks valid, isn't" bug.
  2. Computing the checksum with the wrong digit order or off-by-one weight — the weight is 13 - i for 0-indexed i, not 12 - i or reversed.
  3. Normalizing a phone number by just stripping dashes without handling the +66/66 international prefix — produces an 11-12 digit string that isn't the canonical local form.
  4. Building a PromptPay payload with the wrong CRC algorithm (e.g. plain CRC-16/IBM or a reflected variant) — the spec requires CRC-16/CCITT-FALSE specifically; any other variant produces a QR that fails the bank app's checksum check even though it looks structurally right.
  5. Forgetting that the CRC is computed over the payload string up to and including the literal 6304 prefix, not the full string with a placeholder CRC already in it.
  6. Using proxy type 02 (national ID) with an ID that hasn't been checksum-validated first — a malformed ID produces a QR that scans but routes to nothing.

Code

validate.py — no dependencies:

  • validate_thai_id(id_number) → bool, accepts input with spaces/dashes
  • compute_thai_id_checksum(first_12_digits) → the check digit
  • generate_test_id(first_12_digits) → checksum-valid synthetic ID, for test fixtures only
  • normalize_phone(raw) → canonical 0XXXXXXXXX form
  • build_promptpay_payload(proxy_type, proxy_value, amount=None) → proxy_type is "mobile" or "national_id"
  • crc16_ccitt_false(data: bytes) → the raw CRC, independently testable against the standard catalogue vector

Run python3 validate.py for the self-test — includes a CRC-16/CCITT-FALSE reference check value ("123456789" → 0x29B1, the standard catalogue test vector) plus round-trip checksum generation/validation and full TLV round-trip parsing of a generated PromptPay payload.

Known limitations

  • Checksum validation proves the number is well-formed, not that it belongs to a real, specific person — never treat a passing checksum as identity verification.
  • build_promptpay_payload does not render an image; pass the returned string to a QR-encoding library to get a scannable image.
  • Only mobile-number and national-ID proxy types are implemented; e-Wallet ID proxy (tag 03) is not covered.
  • All example IDs used in this skill's self-test are generated by the checksum function itself — never hardcode or commit a real person's national ID as a "test fixture."

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.