just_validation library

A fluent validation library for Dart inspired by FluentValidation.

This library provides an expressive and easy-to-use way to validate your Dart objects with a fluent, chainable API.

Basic Usage

class UserValidator extends AbstractValidator<User> {
  UserValidator() {
    ruleFor((user) => user.name)
        .notEmpty()
        .withMessage('Name is required')
        .length(2, 50);

    ruleFor((user) => user.email)
        .notEmpty()
        .emailAddress();

    ruleFor((user) => user.age)
        .greaterThanOrEqual(18)
        .when((user) => user.age != null);
  }
}

final validator = UserValidator();
final result = validator.validate(user);

if (!result.isValid) {
  for (var error in result.errors) {
    print('${error.propertyName}: ${error.errorMessage}');
  }
}

Classes

AbstractValidator<T>
Base class for creating validators for type T.
AlphanumericValidator<T>
Validator that checks if a string contains only alphanumeric characters.
AlphaValidator<T>
Validator that checks if a string contains only alphabetic characters.
ArgentineCuitValidator<T>
Validates Argentine CUIT/CUIL Format: 11 digits with Mod 11 checksum
ArgentineDniValidator<T>
Validates Argentine DNI (Documento Nacional de Identidad) Format: 7-8 digits (no checksum)
AsyncContextPredicateValidator<T, TProperty>
Validator that uses a custom asynchronous predicate with access to the entire object.
AsyncPredicateValidator<T, TProperty>
Validator that uses a custom asynchronous predicate function.
AustralianTfnValidator<T>
Validates Australian TFN (Tax File Number) Format: 8-9 digits with Mod 11 checksum
BelgianNationalNumberValidator<T>
Validates Belgian National Number (Rijksregisternummer) Format: 11 digits with Mod 97 checksum
BrazilianCnpjValidator<T>
Validates Brazilian CNPJ (Cadastro Nacional da Pessoa Jurídica) Format: 14 digits with 2 check digits
BrazilianCpfValidator<T>
Validates Brazilian CPF (Cadastro de Pessoas Físicas) Format: 11 digits with 2 check digits
CanadianSinValidator<T>
Validates Canadian SIN (Social Insurance Number) Format: 9 digits with Luhn algorithm
ChileanRutValidator<T>
Validates Chilean RUT (Rol Único Tributario) Format: 8 digits + check digit (K or 0-9)
ChineseIdValidator<T>
Validates Chinese ID (身份证号码) Format: 18 digits with Mod 11 checksum
CollectionExactLengthValidator<T, TElement>
Validator that checks the exact length of a collection.
CollectionMaxLengthValidator<T, TElement>
Validator that checks the maximum length of a collection.
CollectionMinLengthValidator<T, TElement>
Validator that checks the minimum length of a collection.
CollectionNotEmptyValidator<T, TElement>
Validator that checks if a collection is not empty.
CollectionPropertyRule<T, TElement>
Represents a validation rule for a collection property.
ColombianCcValidator<T>
Validates Colombian CC (Cédula de Ciudadanía) Format: 6-10 digits (no checksum)
ContextPredicateValidator<T, TProperty>
Validator that uses a custom predicate with access to the entire object.
CreditCardValidator<T>
Validates that a string is a valid credit card number using Luhn algorithm
DateBetweenValidator<T>
Validator that checks if a DateTime is between two dates (inclusive).
DutchBsnValidator<T>
Validates Dutch BSN (Burgerservicenummer) Format: 9 digits with 11-proof test
EcuadorianCedulaValidator<T>
Validates Ecuadorian Cédula Format: 10 digits with Mod 10 checksum
EmailValidator<T>
Validator that checks if a string is a valid email address.
EqualValidator<T, TProperty>
Validator that checks if a value equals another value.
ExclusiveBetweenValidator<T, TProperty extends Comparable>
Validator that checks if a value is within an exclusive range.
FrenchNationalIdValidator<T>
Validates French National ID (CNI) Format: 12 digits
GermanIdValidator<T>
Validates German ID Number (Personalausweis) Format: 10 alphanumeric characters with checksum
GreaterThanOrEqualValidator<T, TProperty extends Comparable>
Validator that checks if a number is greater than or equal to a specified value.
GreaterThanValidator<T, TProperty extends Comparable>
Validator that checks if a number is greater than a specified value.
HexColorValidator<T>
Validates that a string is a valid hexadecimal color. Supports formats: #RGB, #RRGGBB, #AARRGGBB, and without # prefix.
IBANValidator<T>
Validates that a string is a valid IBAN (International Bank Account Number)
InclusiveBetweenValidator<T, TProperty extends Comparable>
Validator that checks if a value is within an inclusive range.
IndianAadhaarValidator<T>
Validates Indian Aadhaar Format: 12 digits with Verhoeff checksum
IndianPanValidator<T>
Validates Indian PAN (Permanent Account Number) Format: 5 letters + 4 digits + 1 letter (e.g., ABCDE1234F)
InFutureValidator<T>
Validator that checks if a DateTime is in the future.
InlineValidationResult
Result of an inline validation
InPastValidator<T>
Validator that checks if a DateTime is in the past.
IPAddressValidator<T>
Validates that a string is a valid IP address (IPv4 or IPv6)
IPv4Validator<T>
Validates that a string is a valid IPv4 address
IPv6Validator<T>
Validates that a string is a valid IPv6 address
IsAfterOrEqualValidator<T>
Validator that checks if a DateTime is after or equal to another DateTime.
IsAfterValidator<T>
Validator that checks if a DateTime is after another DateTime.
IsBeforeOrEqualValidator<T>
Validator that checks if a DateTime is before or equal to another DateTime.
IsBeforeValidator<T>
Validator that checks if a DateTime is before another DateTime.
ISBNValidator<T>
Validates that a string is a valid ISBN-10 or ISBN-13
IsTodayValidator<T>
Validator that checks if a DateTime is today (ignoring time component).
ItalianFiscalCodeValidator<T>
Validates Italian Fiscal Code (Codice Fiscale) Format: 16 characters (e.g., RSSMRA85M01H501Z)
JwtValidator<T>
Validates that a string is a valid JWT (JSON Web Token) format. Validates structure only: header.payload.signature (3 base64url parts). Does NOT validate the signature or token expiration.
LatitudeValidator<T>
Validates that a number is a valid latitude (-90 to 90)
LengthValidator<T>
Validator that checks string length.
LessThanOrEqualValidator<T, TProperty extends Comparable>
Validator that checks if a number is less than or equal to a specified value.
LessThanValidator<T, TProperty extends Comparable>
Validator that checks if a number is less than a specified value.
LongitudeValidator<T>
Validates that a number is a valid longitude (-180 to 180)
MACAddressValidator<T>
Validates that a string is a valid MAC address
MaxAgeValidator<T>
Validator that checks if a date represents a maximum age.
MaxLengthValidator<T>
Validator that checks maximum string length.
MexicanCurpValidator<T>
Validates Mexican CURP (Clave Única de Registro de Población) Format: 18 characters
MexicanRfcValidator<T>
Validates Mexican RFC (Registro Federal de Contribuyentes) Format: 12-13 characters (12 for companies, 13 for individuals)
MinAgeValidator<T>
Validator that checks if a date represents a minimum age.
MinLengthValidator<T>
Validator that checks minimum string length.
NationalIdValidator<T>
Generic validator that validates based on NationalIdType
NotEmptyValidator<T>
Validator that checks if a string is not empty.
NotEqualValidator<T, TProperty>
Validator that checks if a value does not equal another value.
NotNullValidator<T, TProperty>
Validator that checks if a value is not null.
PolishPeselValidator<T>
Validates Polish PESEL Format: 11 digits with weighted checksum
PortugueseNifValidator<T>
Validates Portuguese NIF (Número de Identificação Fiscal) Format: 9 digits with Mod 11 checksum
PostalCodeValidator<T>
Validates that a string is a valid postal code for 129 countries worldwide
PredicateValidator<T, TProperty>
Validator that uses a custom predicate function.
PropertyEqualValidator<T, TProperty>
Validator that compares a property with another property on the same object.
PropertyNotEqualValidator<T, TProperty>
Validator that checks if a property does not equal another property.
PropertyRule<T, TProperty>
Represents a validation rule for a specific property.
PropertyValidator<T, TProperty>
Base class for property validators.
RegexValidator<T>
Validator that checks if a string matches a regular expression.
SameDayValidator<T>
Validator that checks if two DateTimes are on the same day.
SingaporeNricValidator<T>
Validates Singapore NRIC/FIN Format: 1 letter + 7 digits + 1 letter (e.g., S1234567D)
SpanishDniValidator<T>
Validates Spanish DNI (Documento Nacional de Identidad) Format: 8 digits + 1 letter (e.g., 12345678Z)
SpanishNieValidator<T>
Validates Spanish NIE (Número de Identidad de Extranjero) Format: X/Y/Z + 7 digits + 1 letter (e.g., X1234567L)
UKNationalInsuranceValidator<T>
Validates UK National Insurance Number (NIN) Format: 2 letters + 6 digits + 1 letter (e.g., AB123456C)
UrlValidator<T>
Validator that checks if a string is a valid URL.
UsSsnValidator<T>
Validates US Social Security Number (SSN) Format: 3-2-4 digits (e.g., 123-45-6789)
UUIDValidator<T>
Validates that a string is a valid UUID (v1, v2, v3, v4, or v5)
ValidationContext<T>
Context information for a validation operation.
ValidationFailure
Represents a validation failure for a specific property.
ValidationResult
Represents the result of a validation operation.
WithinDurationValidator<T>
Validator that checks if a DateTime is within a duration from a reference date.

Enums

CascadeMode
Defines how validation should proceed when a rule fails.
NationalIdType
Enum representing all supported national ID types

Mixins

ChecksumAlgorithms
Mixin providing common checksum algorithms for identity document validation.

Extensions

CollectionValidatorExtensions on PropertyRule<T, List<TElement>>
Extension methods for collection property rules.
ComparableValidatorExtensions on PropertyRule<T, TProperty>
Extension methods for Comparable property rules (numbers, DateTime, etc.).
CustomValidatorExtensions on PropertyRule<T, TProperty>
Extension methods for custom validators (predicate-based).
DateTimeValidatorExtensions on PropertyRule<T, DateTime>
Extension methods for DateTime property rules.
EqualityValidatorExtensions on PropertyRule<T, TProperty>
Extension methods for comparison validators.
GPSValidatorExtensions on PropertyRule<T, num>
Extension methods for GPS coordinate validators.
IdentityValidatorExtensions on PropertyRule<T, String>
Extension methods for identity document validation.
InlineGPSValidation on num?
Extension for inline GPS coordinate validation
InlineListValidation on List<T>?
Extension for inline List validation
InlineNumberValidation on T?
Extension for inline number validation
InlineStringValidation on String?
Extension for inline String validation
IsolateValidation on AbstractValidator<T>
Implementación de validación con isolates para plataformas nativas. Para plataformas web, se usa isolate_validation_stub.dart. Extension que añade validación en isolates usando Isolate.run.
NullableValidatorExtensions on PropertyRule<T, TProperty>
Extension methods for nullable property rules.
StringValidatorExtensions on PropertyRule<T, String>
Extension methods for String property rules.

Exceptions / Errors

ValidationException