Skip to content
View Article Network

Taiwan ID Number Validation

When a system needs to validate multiple types of Taiwan identification numbers, it is common to see different APIs written for National IDs, Unified ID numbers, etc. This is because there are many ready-made examples available online, and if validation is needed, one can simply find and copy one. However, when the sources of these validation examples differ, it often leads to inconsistencies in naming and parameters. Of course, those with more sense will adjust different ID validation APIs to follow the same naming conventions and interface formats.

Some people may not have noticed that whether it is a "National Identification Number," "Taiwan Area Resident Certificate Unified ID Number," "Foreign Resident Certificate Unified ID Number," "Homeless ID Number," or "New Foreigner Unified ID Number," they all share the same check digit validation logic, with the only difference being the second digit. Therefore, the correct way to validate ID numbers is to first establish a common underlying layer and then pass the various ID types as parameters to validate the second digit.

Encoding Principles

The complete ID number format is as follows:

Region CodeGender CodeIdentity CodeSerial NumberCheck Digit
A123456789

Gender Code Rules:

ID TypeMaleFemale
National Identification Number12
Taiwan Area Resident Certificate Unified ID NumberAB
Foreign Resident Certificate Unified ID NumberCD
Homeless ID NumberYX
New Foreigner Unified ID Number89

TIP

  • The Homeless ID Number using Y for male and X for female is not a typo. It is speculated that this is due to chromosomal reasons, so the alphabetical order does not follow the male-first convention.
  • After the "Taiwan Area Resident Certificate Unified ID Number" and "Foreign Resident Certificate Unified ID Number" were integrated into the "New Foreigner Unified ID Number," the identity code is now used to distinguish between Taiwan residents and foreign nationals.

The English-to-number mapping is as follows:

1011121314151617341819202122352324252627282932303133

Weighting for each digit:

N0N1N2N3N4N5N6N7N8N9N10
19876543211

Handling of the Gender Code:

  • Numeric: Use directly.
  • Alphabetical: Convert to a number based on the mapping above, then take the last digit.

The check digit calculation formula is as follows: (N0 × 1 + N1 × 9 + N2 × 8 + N3 × 7 + N4 × 6 + N5 × 5 + N6 × 4 + N7 × 3 + N8 × 2 + N9 × 1 + N10 × 1) % 10 = 0

Example

Since I do not want to rewrite the validation code, I have provided a link containing the validation code I wrote previously. If you need it, you can extract the validation portion. Code link: IdCardValidator.

Change Log

  • 2023-01-16 Initial document creation.