Skip to content

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

Merged
koblas merged 1 commit into
koblas:mainfrom
gccbb02498:fix/tw-ubn-2023-checksum
Jul 8, 2026
Merged

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

Conversation

@gccbb02498

Copy link
Copy Markdown
Contributor

Problem

The Taiwan Unified Business Number (統一編號 / UBN) validator 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 available number space. The 8-digit 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 divisible by 5 but not 10) as InvalidChecksum.

Note: upstream python-stdnum still uses the mod-10 rule, so this brings stdnum-js in line with the current official spec ahead of it.

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>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request updates the UBN validation logic to align with the official 2023 Ministry of Finance specification change in Taiwan. By relaxing the checksum requirement from divisible-by-10 to divisible-by-5, the validator now correctly accepts newer business numbers while remaining fully backward compatible with older ones.

Highlights

  • Checksum Logic Update: Updated the Taiwan Unified Business Number (UBN) validation logic to accept numbers where the weighted digit sum is divisible by 5, complying with the 2023 Ministry of Finance regulation update.
  • Backward Compatibility: Maintained support for legacy UBNs (divisible by 10) while ensuring the new rule correctly validates numbers issued after April 2023.
  • Special Case Handling: Updated the special case logic for the 7th digit being '7' to correctly account for the new modulo 5 requirement.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Taiwan Unified Business Number (UBN) validation logic to support the relaxed check-digit rules introduced on 2023-04-01, where the weighted digit sum only needs to be divisible by 5 instead of 10. It also updates the documentation and adds corresponding test cases for old-rule numbers, new-rule numbers, and the 7th-digit special case. There are no review comments, and I have no additional feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@koblas koblas merged commit e83579a into koblas:main Jul 8, 2026
2 checks passed
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.

2 participants