Skip to content

fix(tw/ubn): accept 2023 relaxed check-digit rule (divisible by 5)#1

Closed
gccbb02498 wants to merge 1 commit into
mainfrom
fix/tw-ubn-2023-checksum
Closed

fix(tw/ubn): accept 2023 relaxed check-digit rule (divisible by 5)#1
gccbb02498 wants to merge 1 commit into
mainfrom
fix/tw-ubn-2023-checksum

Conversation

@gccbb02498

@gccbb02498 gccbb02498 commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Problem

The Taiwan Unified Business Number (統一編號 / UBN) validator still uses the old rule where the weighted digit sum must be divisible by 10. Effective 2023-04-01, Taiwan's Ministry of Finance relaxed the check-digit logic from "divisible by 10" to "divisible by 5" to expand the number space. The format is unchanged, and every old (divisible-by-10) number is also divisible by 5, so the change is fully backward compatible.

As a result, the current implementation incorrectly rejects legitimate UBNs issued after 2023 (those that are only divisible by 5) as InvalidChecksum.

Fix

  • Relax the checksum from sum % 10 === 0 to sum % 5 === 0.
  • Keep the special case for the 7th digit being 7 (7 * 4 = 28, whose digit sum is 10 and may be counted as either 1 or 0), now evaluated against the mod-5 remainder.

Tests

UBN Description Result
04595257 Old rule, divisible by 10 (TSMC, real number) valid
00501503 Existing old-rule test case valid
00501508 New rule, divisible by 5 (not by 10) valid
00000074 New rule + 7th-digit-is-7 special case valid
00501502 Wrong check digit InvalidChecksum

jest src/tw/ubn.spec.ts → 7 passed. lint and tsc both pass.

Reference

🤖 Generated with Claude Code

Effective 2023-04-01, Taiwan's Ministry of Finance changed the Unified
Business Number (統一編號) check-digit logic so the weighted digit sum only
needs to be divisible by 5 (previously 10), expanding the number space while
keeping the same 8-digit format. Every old, divisible-by-10 number is still
divisible by 5, so existing numbers remain valid.

- Relax the checksum from `sum % 10 === 0` to `sum % 5 === 0`.
- Keep the 7th-digit-is-7 special case (7*4=28 sums to 10), now checked
  against the mod-5 remainder.
- Add tests: an old-rule number (04595257), a new divisible-by-5 number
  (00501508), and a new 7th-digit special case (00000074).

Ref: https://www.fia.gov.tw/singlehtml/3?cntId=c4d9cff38c8642ef8872774ee9987283

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gccbb02498

Copy link
Copy Markdown
Owner Author

Superseded by upstream PR koblas#159 — contributing the fix directly to the upstream project.

@gccbb02498 gccbb02498 closed this Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant