TwIdValidator

Taiwan national ID, BAN and mobile phone validation — auto-detection of all three ID kinds, detailed parse results, test-data generation. Zero dependencies, thread-safe.

Core Features

🪪

All Three ID Kinds

National ID, new-style UI number (2021+) and old-style ARC number auto-detected, with gender and household region parsing.

🏢

2021 BAN Rule

Full support for the April 2021 checksum rule (multiple of 5) and the 7th-digit-7 special case.

📱

Phone Validation + Normalize

Strict 10-digit 09 check; TryNormalize handles +886, spaces, dashes, parentheses and full-width digits.

🧪

Test-data Generator

Generates checksum-valid sample numbers, reproducible with a seed; format-valid only, never real persons.

Quick Start

1. Install the package

dotnet add package Ozakboy.TaiwanKit.TwIdValidator

2. Validate immediately

using Ozakboy.TaiwanKit.TwIdValidator;

TwId.IsValid("A123456789");          // true
TwBan.IsValid("04595257");           // true
TwPhone.IsValid("0912345678");       // true

TwIdResult r = TwId.Validate("A123456789");
// r.Kind → NationalId, r.Gender → Male, r.RegionName → "臺北市"

3. Normalize & generate test data

// 正規化 +886 / 分隔符 / 全形數字
TwPhone.TryNormalize("+886-912-345-678", out string n);  // n = "0912345678"

// 產生檢核碼合法的測試假資料(不對應真實人物)
TwId.Generate(TwIdKind.NationalId, Gender.Female);
TwBan.Generate();