API Reference

TwId — National ID / UI numbers

MemberReturnsDescription
IsValid(string?)boolValidates all three ID kinds (auto-detected); false for null/empty, never throws
Validate(string?)TwIdResultDetailed validation result
Generate(TwIdKind, Gender?, int? seed)stringGenerates a checksum-valid sample ID

TwIdResult

PropertyTypeDescription
IsValidboolWhether the number is valid
FailureValidationFailureFailure reason; None when valid
KindTwIdKind?Number kind; null when the format is unrecognizable
GenderGender?Gender; null when unrecognizable
RegionNamestring?Household (first registration) region; obsolete codes marked "(已停用)"

TwIdKind

ValueDescription
NationalIdNational ID for citizens (2nd char 1/2)
NewResidentIdNew-style UI number (2nd char 8/9, 2021+)
OldResidentIdOld-style ARC number (first 2 chars are letters, valid until 2031)

TwBan — Business administration number

MemberReturnsDescription
IsValid(string?)bool8-digit BAN validation (2021 rule + 7th-digit-7 special case)
Validate(string?)BanResultDetailed result (IsValid + Failure)
Generate(int? seed)stringGenerates a checksum-valid sample BAN

TwPhone — Mobile phone number

MemberReturnsDescription
IsValid(string?)boolStrict validation: 10 digits starting with 09
Validate(string?)PhoneResultDetailed result
TryNormalize(string?, out string)boolNormalizes +886/886, spaces, dashes, parentheses, dots and full-width digits, then validates
Generate(int? seed)stringGenerates a format-valid sample number

ValidationFailure

ValueDescription
NoneValidation passed
NullOrEmptyNull, empty or whitespace-only input
InvalidLengthWrong length
InvalidFormatCharacter kind or position violates the rule
InvalidChecksumChecksum mismatch

Exception behavior

Validation paths never throw. The only throwing case: TwId.Generate throws ArgumentOutOfRangeException for an undefined TwIdKind.