On this page

Skip to content

Taiwan ID Number Verification

When a system requires the validation of multiple types of Taiwan identification numbers, it is common to see developers write separate APIs for National IDs, Unified ID numbers, etc. This is often because there are many ready-made examples available online, and when validation is needed, one can simply copy and paste. However, when validation examples come from different sources, it often leads to inconsistencies in naming and parameter structures. Naturally, more experienced developers will standardize these different ID validation APIs to follow the same naming conventions and interface formats.

Some may not have noticed that whether it is a "National Identification Number," "Taiwan Area Resident Certificate Number," "Alien Resident Certificate Number," "Homeless ID Number," or the "New Alien Resident Certificate Number," they all share the same check digit validation logic, with the only difference being the second digit. Therefore, the correct approach to ID validation is to first establish a common underlying logic 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 CodeSequence CodeCheck Digit
A123456789

Gender code rules:

ID TypeMaleFemale
National Identification Number12
Taiwan Area Resident Certificate NumberAB
Alien Resident Certificate NumberCD
Homeless ID NumberYX
New Alien Resident Certificate Number89

TIP

  • The fact that the Homeless ID Number uses Y for male and X for female is not a typo. It is speculated that this is due to chromosomal factors, which is why the alphabetical order does not follow the standard male-then-female sequence.
  • After the "Taiwan Area Resident Certificate Number" and "Alien Resident Certificate Number" were integrated into the "New Alien Resident Certificate 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 gender codes:

  • Numbers: Use directly.
  • Letters: Convert to numbers based on the mapping above, then take the last digit (units 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 to 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 version of the document created.