just_validation 0.4.0
just_validation: ^0.4.0 copied to clipboard
A simple and flexible validation library for Dart that provides validators for common use cases.
Changelog #
All notable changes to this project will be documented in this file.
0.4.0 - 2026-01-26 #
Added - DateTime Validators #
- DateTime validation support: Complete set of validators for date/time validation
- New DateTime validators:
isAfter(date)- Date must be after specified dateisAfterOrEqual(date)- Date must be after or equal to specified dateisBefore(date)- Date must be before specified dateisBeforeOrEqual(date)- Date must be before or equal to specified dateisBetween(from, to)- Date must be within range (inclusive)isInPast()- Date must be in the pastisInFuture()- Date must be in the futureisToday()- Date must be today (ignores time)isSameDay(date)- Date must be same day as specified dateisWithinDuration(date, duration)- Date must be within duration of reference dateminAge(years)- Validates minimum age (e.g., must be 18+)maxAge(years)- Validates maximum age
- All DateTime validators support
nowProviderparameter for testing
Added - International Identity Document Validators #
- 26 identity document validators covering 4 continents:
Europe (10 validators):
- 🇪🇸
dni()/spanishDni()- Spanish DNI (8 digits + letter with checksum) - 🇪🇸
nie()/spanishNie()- Spanish NIE (X/Y/Z + 7 digits + letter) - 🇬🇧
nin()/ukNationalInsurance()- UK National Insurance Number - 🇩🇪
germanId()- German Personalausweis (10 chars with checksum) - 🇮🇹
codiceFiscale()/italianFiscalCode()- Italian Fiscal Code (16 chars) - 🇵🇹
nif()/portugueseNif()- Portuguese NIF (9 digits, Mod 11) - 🇳🇱
bsn()/dutchBsn()- Dutch BSN (9 digits, 11-proof) - 🇧🇪
belgianNationalNumber()- Belgian National Number (11 digits, Mod 97) - 🇵🇱
pesel()/polishPesel()- Polish PESEL (11 digits) - 🇫🇷
frenchNationalId()- French CNI (12 digits)
Americas (11 validators):
- 🇺🇸
ssn()/usSsn()- US Social Security Number (area/group validation) - 🇲🇽
curp()/mexicanCurp()- Mexican CURP (18 chars with checksum) - 🇲🇽
rfc()/mexicanRfc()- Mexican RFC (12-13 chars) - 🇧🇷
cpf()/brazilianCpf()- Brazilian CPF (11 digits, Mod 11) - 🇧🇷
cnpj()/brazilianCnpj()- Brazilian CNPJ (14 digits, Mod 11) - 🇦🇷
argentineDni()- Argentine DNI (7-8 digits) - 🇦🇷
cuit()/cuil()/argentineCuit()- Argentine CUIT/CUIL (Mod 11) - 🇨🇱
rut()/chileanRut()- Chilean RUT (Mod 11 with K) - 🇨🇦
sin()/canadianSin()- Canadian SIN (Luhn algorithm) - 🇨🇴
colombianCc()- Colombian Cédula de Ciudadanía - 🇪🇨
ecuadorianCedula()- Ecuadorian Cédula (Mod 10)
Asia & Oceania (5 validators):
- 🇨🇳
chineseId()- Chinese ID (18 digits with date and Mod 11) - 🇮🇳
aadhaar()/indianAadhaar()- Indian Aadhaar (Verhoeff algorithm) - 🇮🇳
pan()/indianPan()- Indian PAN (10 chars) - 🇦🇺
tfn()/australianTfn()- Australian TFN (Mod 11) - 🇸🇬
nric()/singaporeNric()- Singapore NRIC/FIN
Added - Generic National ID Validator #
nationalId(NationalIdType type)- Generic validator using enumNationalIdTypeenum with 26 document typesNationalIdType.fromCountry(countryCode, docType)- Dynamic type resolution
Added - Checksum Algorithms Mixin #
ChecksumAlgorithmsmixin with reusable algorithms:luhnCheck()- Luhn/Mod 10 algorithmmod11Checksum()- Mod 11 with custom weightsmod97()- Mod 97 algorithm (IBAN-style)verhoeffCheck()- Verhoeff algorithm
Added - Additional Validators #
hexColor()- Validates hexadecimal color strings (#RGB, #RRGGBB, #AARRGGBB)- Option
requireHashto require # prefix - Option
allowAlphato allow 8-digit colors with alpha channel
- Option
jwt()- Validates JWT (JSON Web Token) format- Validates 3-part structure (header.payload.signature)
- Validates base64url encoding
- Validates header contains "alg" field
Added - Tests #
- 17 new tests for DateTime validators
- 45 new tests for identity validators
- 12 new tests for HexColor and JWT validators
- Total new tests: 74
Statistics #
- Total validators: 58+ (30 basic + 10 advanced + 12 DateTime + 26 identity)
- Total countries with identity support: 18
- Total tests: 215+ (all passing)
0.3.0 - 2026-01-26 #
Added - Isolate Validation (Parallel Processing) #
- Isolate validation support: Execute validations in separate isolates using
Isolate.run - New methods for parallel validation:
validateIsolate(instance): Validate a single instance in an isolatevalidateManyIsolate(instances): Validate multiple instances in an isolate (batch processing)validateAsyncIsolate(instance): Async validation in an isolate
- No dependencies required: Uses Dart SDK 2.19+ built-in
Isolate.run - Universal support: Works in Flutter apps, backend Dart, CLI tools, and web
- Performance optimized: Perfect for batch processing (1000+ objects) and computationally expensive validations
- 11 new tests: Complete test coverage for isolate validation
Technical Details #
- Requires Dart SDK 2.19 or higher
- Zero additional dependencies (uses
dart:isolate) - Overhead: ~5-10ms per isolate creation
- Ideal for:
- CSV/Excel import (1000+ records)
- Background batch processing
- Complex validations (50+ rules)
- Flutter apps that cannot block UI
- Backend data processing
0.2.0 - 2026-01-25 #
Added - Advanced Validators #
- IP Address validation: IPv4, IPv6, or both formats
- MAC Address validation: Supports colon, hyphen, and no-separator formats
- GPS Coordinates validation: Latitude (-90 to 90) and Longitude (-180 to 180)
- Credit Card validation: Luhn algorithm, 13-19 digits, supports spaces/hyphens
- IBAN validation: Full Mod-97 algorithm, 52 countries supported
- ISBN validation: ISBN-10 and ISBN-13 with checksum validation
- UUID validation: Versions 1, 2, 3, 4, and 5
- Postal Code validation: 129 countries worldwide organized by region
- América del Norte (12): US, CA, MX, CR, PA, GT, SV, HN, NI, CU, DO, PR
- América del Sur (10): BR, AR, CL, CO, PE, VE, EC, BO, PY, UY
- Europa Occidental (18): GB, FR, DE, ES, IT, NL, BE, CH, AT, PT, IE, LU, MC, AD, SM, LI, VA, GI
- Europa Nórdica (5): SE, NO, DK, FI, IS, FO, GL
- Europa Oriental (25): PL, CZ, SK, HU, RO, BG, HR, SI, EE, LV, LT, UA, BY, MD, RS, BA, MK, AL, GR, CY, MT, ME, XK
- Rusia y Asia Central (5): RU, KZ, AM, AZ, GE
- Asia Oriental (6): JP, CN, KR, TW, HK, MO
- Sudeste Asiático (10): TH, VN, MY, SG, ID, PH, MM, KH, LA, BN
- Asia del Sur (7): IN, PK, BD, LK, NP, BT, MV
- Oriente Medio (13): TR, IL, SA, AE, QA, KW, BH, OM, JO, LB, IQ, IR, PS
- África (13): ZA, EG, MA, DZ, TN, LY, KE, NG, ET, GH, MR, MU, LC
- Oceanía (5): AU, NZ, PG, FJ, VG
Added - Inline Validation Extensions #
- All 8 advanced validators available as inline extensions
.validateIPv4,.validateIPv6,.validateMACAddress.validateLatitude,.validateLongitude.validateCreditCard,.validateIBAN,.validateISBN,.validateUUID
Added - Examples and Tests #
- New example:
advanced_validation_example.dartdemonstrating all advanced validators - 39 new tests for advanced validators (Validator Pattern + Inline)
- Total tests: 104 (all passing ✅)
Statistics #
- Total validators: 28 (20 basic + 8 advanced)
- Total tests: 104 (100% passing)
- Total lines of code: ~2,762 lines
- Code coverage: 100% on core functionality
0.1.0 #
Initial Release #
Core Features
- ✅ Fluent API for building validation rules
- ✅ Strong typing and null-safety support
- ✅ Comprehensive built-in validators
String Validators
notEmpty()- Ensures string is not emptynotNull()- Ensures value is not nulllength(min, max)- Validates string length rangeminLength(length)- Validates minimum lengthmaxLength(length)- Validates maximum lengthexactLength(length)- Validates exact lengthemailAddress()- Validates email formaturl()- Validates URL formatmatches(regex)- Validates against regex patternalpha()- Validates alphabetic characters onlyalphanumeric()- Validates alphanumeric characters only
Number Validators
greaterThan(value)- Value must be greater than specifiedgreaterThanOrEqual(value)- Value must be greater than or equallessThan(value)- Value must be less than specifiedlessThanOrEqual(value)- Value must be less than or equalinclusiveBetween(from, to)- Value must be within inclusive rangeexclusiveBetween(from, to)- Value must be within exclusive range
Comparison Validators
equal(value)- Value must equal specified valuenotEqual(value)- Value must not equal specified valueequalTo(property)- Value must equal another propertynotEqualTo(property)- Value must not equal another property
Collection Validators
notEmpty()- Collection must not be emptyminLength(length)- Collection must have minimum itemsmaxLength(length)- Collection must have maximum itemsexactLength(length)- Collection must have exact number of items
Custom Validators
must(predicate, message)- Custom synchronous validationmustWith(predicate, message)- Custom validation with object contextmustAsync(predicate, message)- Custom asynchronous validationmustAsyncWith(predicate, message)- Custom async validation with context
Advanced Features
- Conditional validation with
when()andunless() - Custom error messages with
withMessage() - Cascade modes (continue or stop on first failure)
- Nested object validation with
ruleForEach() - Asynchronous validation support
- Rich validation results with detailed error information
Documentation
- Comprehensive README with examples
- API documentation with dartdoc comments
- Example applications demonstrating:
- Basic validation
- Complex nested validation
- Asynchronous validation
- Flutter integration
Testing
- 47+ unit tests covering all validators
- Integration tests for complex scenarios
- 100% code coverage on core functionality