DcsvIo.D2.Validation
0.1.31
dotnet add package DcsvIo.D2.Validation --version 0.1.31
NuGet\Install-Package DcsvIo.D2.Validation -Version 0.1.31
<PackageReference Include="DcsvIo.D2.Validation" Version="0.1.31" />
<PackageVersion Include="DcsvIo.D2.Validation" Version="0.1.31" />
<PackageReference Include="DcsvIo.D2.Validation" />
paket add DcsvIo.D2.Validation --version 0.1.31
#r "nuget: DcsvIo.D2.Validation, 0.1.31"
#:package DcsvIo.D2.Validation@0.1.31
#addin nuget:?package=DcsvIo.D2.Validation&version=0.1.31
#tool nuget:?package=DcsvIo.D2.Validation&version=0.1.31
DcsvIo.D2.Validation
Audience: backend .NET service engineers integrating the validators via DI - email, phone, and postal-code validation backed by libphonenumber-csharp and a ported postcode-validator dataset.
Default implementations of IEmailValidator, IPhoneValidator and IPostalCodeValidator from
DcsvIo.D2.Validation.Abstractions.
Install
dotnet add package DcsvIo.D2.Validation
Validators
| Validator | Interface | Backing |
|---|---|---|
DefaultEmailValidator |
IEmailValidator |
ASCII-only regex (anchored, bounded - total length 1-254, local part 1-64) |
DefaultPhoneValidator |
IPhoneValidator |
libphonenumber-csharp 9.0.31 (Apache-2.0) - parse + E.164 format |
DefaultPostalCodeValidator |
IPostalCodeValidator |
Per-country regex map embedded from the shared contracts/validation/postal-code-regexes.json dataset (ported from postcode-validator@3.10.9, with a UK/GB correction) |
Contract
Every Validate(...) method returns D2Result<string>:
- Success -
Ok(normalized)wherenormalizedis trimmed + lowercased (email) or trimmed + uppercased (postal code) or E.164-formatted (phone). - Failure -
ValidationFailed(inputErrors: [new InputError("<field>", [TK.Common.Validation.<KEY>_INVALID])]).
Field names: "email", "phone", "postalCode".
Empty or whitespace input produces the same *_INVALID key as structurally invalid input.
Postal-code dataset
The per-country regex map lives in contracts/validation/postal-code-regexes.json -
the single cross-runtime source of truth, read by both runtimes. This project
embeds it as a build-time EmbeddedResource (Link'd to the logical name
PostalCodeRegexData.json, so the manifest-resource lookup in
PostalCodeRegexData.cs resolves unchanged); the TypeScript @dcsv-io/d2-validation
package embeds the same patterns in its generated postal-code-regexes.g.ts. Neither
runtime keeps a hand-written copy.
The dataset is ported from postcode-validator@3.10.9 with one deliberate
correction: the UK and GB patterns used [A-z] (ASCII 65-122, which
wrongly includes the six punctuation chars [ \ ] ^ _ ` between Z and
a) - an upstream bug - replaced with [A-Za-z]. Patterns that lacked both
^ and $ anchors in the source were wrapped as ^(?:...)$; the wrapped
entries are: GI, BT, AL, CU, UM, AI, AF, SD, VC, TA, NA,
EH, BL, TZ, AC, VG, MZ, MF, MM, SV, IR.
Fail-closed: an unknown or null country code always returns ValidationFailed -
there is no fallback to a permissive global-range pattern.
To update the dataset, edit contracts/validation/postal-code-regexes.json and
its $comment version stamp, then regenerate the TypeScript package's
postal-code-regexes.g.ts. This project picks up the change on its next build.
DI Registration
services.AddValidation();
AddValidation() registers IEmailValidator, IPhoneValidator and IPostalCodeValidator with
TryAddSingleton. To override one, call services.Replace(...) after AddValidation().
Dependencies
DcsvIo.D2.Validation.Abstractions- theIEmailValidator,IPhoneValidator, andIPostalCodeValidatorcontracts this package implements.DcsvIo.D2.Result-D2Result<string>return type and semantic factories.DcsvIo.D2.Geo.Abstractions-CountryCodeparameter onIPhoneValidatorandIPostalCodeValidator.DcsvIo.D2.I18n.Abstractions-TK.Common.Validation.*_INVALIDtranslation keys returned in theInputErrorfields ofD2Result.DcsvIo.D2.Utilities-Falsey()for null / empty / whitespace input guards.libphonenumber-csharp 9.0.31- phone-number parsing and E.164 normalization (Apache-2.0). The version is pinned exactly: the accept/reject boundary shifts between minor releases, so the pin keeps behavior stable across the .NET and TypeScript parity fixtures.
Telemetry
No telemetry - pure synchronous validators. Consumers instrument the call sites in their own OTel setup.
Configuration
No configuration - the only internal constant is the 50 ms regex match timeout, an internal defense-in-depth setting not exposed to consumers.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- DcsvIo.D2.Geo.Abstractions (= 0.1.29)
- DcsvIo.D2.I18n.Abstractions (= 0.1.6)
- DcsvIo.D2.I18n.Keys (= 0.3.4)
- DcsvIo.D2.Result (= 0.5.8)
- DcsvIo.D2.Utilities (= 0.3.10)
- DcsvIo.D2.Validation.Abstractions (= 0.1.29)
- JetBrains.Annotations (>= 2025.2.4)
- libphonenumber-csharp (>= 9.0.31)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Options (>= 10.0.7)
- Microsoft.IdentityModel.Tokens (>= 8.18.0)
- NodaTime (>= 3.2.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.