REGEXVAULTv2.0
Identity & PII/National Identity Numbers
Verified Safe

Hong Kong HKID Number Regex for JavaScript

/^([A-Z]{1,2})([0-9]{6})\(([0-9A])\)$/i

What this pattern does

This page provides a well-structured, multi-part regular expression for matching hong kong hkid number, ported and verified for JavaScript. Identity and credential patterns need both correctness and safety, since they're frequent targets for adversarial input. The snippet below is ready to drop into your JavaScript project — whether you're validating in an Express middleware, a Next.js API route, or a client-side form.

Javascript Implementation

Javascript
// Hong Kong HKID Number
// ReDoS-safe | RegexVault — Identity & PII > National Identity Numbers

const hongKongHkidNumberRegex = /^([A-Z]{1,2})([0-9]{6})\(([0-9A])\)$/i;

function validateHongKongHkidNumber(input: string): boolean {
  return hongKongHkidNumberRegex.test(input);
}

// Example
console.log(validateHongKongHkidNumber("A123456(7)")); // true

Test Cases

Matches (Valid)
Rejects (Invalid)
A123456(7)A1234567
AB123456(3)A12345(7)
Z999999(A)A1234567(7)
A123456(0)123456(7)
A123456(B)

When to use this pattern

This pattern is drawn from the Identity & PII > National Identity Numbers category and carries a ReDoS-safe certification. That matters for JavaScript developers because especially critical in long-running Node.js event loops where a ReDoS vulnerability can block the entire process. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

Check character A represents 10 in the checksum. One-letter prefixes (A-Z) are issued chronologically; two-letter prefixes (AA-ZZ) started when the single-letter range was exhausted. Some older cards use lowercase or different formats.

Technical Notes

Structure: 1-2 uppercase letters + 6 digits + check character (0-9 or A) in parentheses. A single letter prefix is padded with a space for checksum calculation. The check character is computed via weighted sum mod 11.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern