fix(tw/ubn): accept 2023 relaxed check-digit rule (divisible by 5)#1
Closed
gccbb02498 wants to merge 1 commit into
Closed
fix(tw/ubn): accept 2023 relaxed check-digit rule (divisible by 5)#1gccbb02498 wants to merge 1 commit into
gccbb02498 wants to merge 1 commit into
Conversation
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>
Owner
Author
|
Superseded by upstream PR koblas#159 — contributing the fix directly to the upstream project. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
sum % 10 === 0tosum % 5 === 0.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
0459525700501503005015080000007400501502jest src/tw/ubn.spec.ts→ 7 passed. lint and tsc both pass.Reference
https://www.fia.gov.tw/singlehtml/3?cntId=c4d9cff38c8642ef8872774ee9987283
🤖 Generated with Claude Code