DcsvIo.D2.Validation
0.1.1
dotnet add package DcsvIo.D2.Validation --version 0.1.1
NuGet\Install-Package DcsvIo.D2.Validation -Version 0.1.1
<PackageReference Include="DcsvIo.D2.Validation" Version="0.1.1" />
<PackageVersion Include="DcsvIo.D2.Validation" Version="0.1.1" />
<PackageReference Include="DcsvIo.D2.Validation" />
paket add DcsvIo.D2.Validation --version 0.1.1
#r "nuget: DcsvIo.D2.Validation, 0.1.1"
#:package DcsvIo.D2.Validation@0.1.1
#addin nuget:?package=DcsvIo.D2.Validation&version=0.1.1
#tool nuget:?package=DcsvIo.D2.Validation&version=0.1.1
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 the three validator contracts 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 imports the same file directly. Neither runtime keeps its own 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 — both runtimes pick up the change on their next build.
DI Registration
services.AddValidation();
All three validators are registered via TryAddSingleton; override any with
services.Replace(...) after calling 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 carried inD2ResultInputErrorfields.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). Exact version pin; accept/reject boundary shifts between minor releases, so the pin keeps behavior stable across .NET and TS 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.1)
- DcsvIo.D2.I18n.Abstractions (>= 0.1.1)
- DcsvIo.D2.I18n.Keys (>= 0.1.1)
- DcsvIo.D2.Result (>= 0.1.1)
- DcsvIo.D2.Utilities (>= 0.1.1)
- DcsvIo.D2.Validation.Abstractions (>= 0.1.1)
- dotenv.net (>= 4.0.2)
- JetBrains.Annotations (>= 2025.2.4)
- libphonenumber-csharp (>= 9.0.31)
- Microsoft.EntityFrameworkCore (>= 10.0.7)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.7)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Caching.Memory (>= 10.0.7)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.7)
- Microsoft.Extensions.DependencyInjection (>= 10.0.7)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Logging (>= 10.0.7)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.7)
- Microsoft.Extensions.Options (>= 10.0.7)
- Microsoft.IdentityModel.Tokens (>= 8.16.0)
- NodaTime (>= 3.2.2)
- Npgsql (>= 10.0.2)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 10.0.1)
- Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime (>= 10.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.