validart library
Type-safe validation for Dart, inspired by Zod.
A schema is a value, not a callback: V builds one through fluent factories (V.string, V.int, V.map, V.object), and the result can be composed, reused and shared between client and server. Running a schema against an input walks a two-phase pipeline — pre-processing, then validation — and yields a VResult: either a VSuccess carrying the normalized value or a VFailure carrying a list of VError.
Every VError carries a machine-readable VError.code, a human-readable VError.message resolved through the active VLocale, and a VError.path locating it inside nested maps, objects and arrays. The codes themselves are constants on VCode and its per-type siblings (VStringCode, VNumberCode, VDateCode, …), which is what makes the messages translatable without touching the schemas.
The package has no runtime dependencies and no code generation: VObject validates instances of your own classes through field extractor callbacks the compiler checks, and VMap validates the JSON-like maps those classes are built from — with the same schema.
final schema = V.map({
'email': V.string().email(),
'age': V.int().min(18),
});
print(schema.validate({'email': 'user@mail.com', 'age': 30})); // true
print(schema.errors({'email': 'nope', 'age': 30})!.first.code); // invalid_email
See also:
Classes
- AmexBrand Extensibility
- Matches American Express cards.
-
AsyncValidator<
T> Extensibility - Abstract base class for async validators.
- CaPostalCodePattern Extensibility
-
Matches Canadian postal codes (
A1A 1A1— space optional). - CardBrandPattern Extensibility
- A pluggable credit-card brand matching strategy.
- CaSinPattern Extensibility
- Matches Canadian Social Insurance Numbers — 9 digits with Luhn check.
- DinersBrand Extensibility
- Matches Diners Club cards.
- DiscoverBrand Extensibility
- Matches Discover cards.
- E164PhonePattern Extensibility
-
Default phone pattern — validates E.164 format (
+followed by 2–15 digits). - JcbBrand Extensibility
- Matches JCB cards.
- LicensePlatePattern Extensibility
- A pluggable license-plate validation strategy.
- MastercardBrand Extensibility
- Matches Mastercard cards.
- PhonePattern Extensibility
- A pluggable phone-number validation strategy.
- PostalCodePattern Extensibility
- A pluggable postal-code validation strategy.
- TaxIdPattern Extensibility
- A pluggable tax-identifier validation strategy.
- UkNiNumberPattern Extensibility
-
Matches UK National Insurance numbers (
AB123456C). - UkPlatePattern Extensibility
-
Matches UK license plates in the current format (post-2001):
two letters + two digits + three letters, with an optional space
between the two groups (
AB12 CDEorAB12CDE). - UkPostcodePattern Extensibility
- Matches UK postcodes (common format; full RFC is more permissive).
- UsSsnPattern Extensibility
-
Matches US Social Security Numbers (
123-45-6789or123456789). - UsZipPattern Extensibility
-
Matches US ZIP codes (
12345or12345-6789). - V Core
- Entry point for creating validation schemas.
-
Validator<
T> Extensibility - Abstract base class for all validators.
-
VArray<
T> Containers -
Validates
List<T>values, applying the element schema to each item. - VArrayCode Internationalization
- Error codes emitted by VArray and its validators.
- VBool Types
- Validates bool values.
- VBoolCode Internationalization
- Error codes emitted by VBool and its validators.
- VCode Internationalization
- Machine-readable error code constants used by validators.
- VCoerce Core
- Provides coercion schemas that convert input values to the target type.
- VDate Types
- Validates DateTime values.
- VDateCode Internationalization
- Error codes emitted by VDate and its validators.
- VDouble Types
- Validates double values.
- VDoubleCode Internationalization
- Error codes emitted by VDouble and its validators.
-
VEnum<
T extends Enum> Types - Validates that a value belongs to a set of enum values.
- VEnumCode Internationalization
- Error codes emitted by VEnum and its validators.
- VError Core
- Represents a single validation error.
-
VFailure<
T> Core - A failed validation result containing the list of errors.
- VInt Types
- Validates int values.
- VIntCode Internationalization
- Error codes emitted by VInt and its validators.
- VisaBrand Extensibility
- Matches Visa cards.
-
VLiteral<
T> Types - Validates that a value is exactly equal to the expected literal.
- VLiteralCode Internationalization
- Error codes emitted by VLiteral and its validators.
- VLocale Internationalization
- Provides locale-aware error message translations.
- VMap Containers
-
Validates
Map<String, dynamic>values against a field schema. - VMapCode Internationalization
- Error codes emitted by VMap and its validators.
-
VNumber<
T extends num> Types - Abstract base for numeric validation types (VInt and VDouble).
- VNumberCode Internationalization
- Error codes shared by VInt and VDouble — range and sign checks that apply to any numeric value.
-
VObject<
T> Containers -
Validates class/entity instances of type
Tvia type-safe field extraction callbacks. - VObjectCode Internationalization
- Error codes emitted by VObject and its validators.
-
VResult<
T> Core - The result of a validation operation.
- VString Types
- Validates String values.
- VStringCode Internationalization
- Error codes emitted by VString and its validators.
-
VSuccess<
T> Core - A successful validation result containing the parsed value.
-
VTransformed<
I, O> Types - Wraps a schema and transforms its output to a different type.
-
VTransformedAsync<
I, O> Types - Wraps a schema and asynchronously transforms its output to a different type.
-
VType<
T> Core - Abstract base for all validation types.
- VUnion Types
- Validates that a value matches at least one of the given schemas.
- VUnionCode Internationalization
- Error codes emitted by VUnion and its validators.
Enums
- CountryCodeFormat Extensibility
-
Controls whether a leading international dialing code (e.g.
+1,+55,+44) is expected on a phone number. - RefineStage Core
- Controls when a VMap.refineField, VObject.refineField or VObject.refineFieldRaw callback runs in the container pipeline.
- UuidVersion Extensibility
- Supported UUID versions for filtering validation.
- ValidationMode Core
- Controls which formatted variants a pattern accepts.
Extensions
- VTypeApplyIf on V Core
-
Conditional schema construction. Applies a
buildertransformation to the receiver only whenconditionistrue, returning the receiver unchanged otherwise.
Exceptions / Errors
- VAsyncRequiredException Core
-
Thrown by synchronous consumers (
parse,validate,safeParse,errors) when the schema contains async steps (added viarefineAsync). - VException Core
- Exception thrown by VType.parse when validation fails.