DFValidator
A powerful, fluent validation library for Delphi applications that makes data validation clean and easy
- Active · last change 4-28-2025
- ★ 7 on GitHub
README
DFValidator
A powerful, fluent validation library for Delphi applications that makes data validation clean and easy.
Features
- Fluent API for building validation rules
- Built-in validators for common data types (strings, integers, dates, emails)
- Easy extensibility to create custom validators
- Detailed validation results with custom error messages
- Zero external dependencies
Installation
- Add
DFValidator.pasto your project - Add
DFValidatorto your unit's uses clause - Start validating!
Quick Example
uses
DFValidator;
// Example 1: Validate username
var
Username: string;
ValidationResult: TDFValidationResult;
begin
Username := 'john123';
ValidationResult := TDFValidate.String
.Required
.MinLength(5)
.MaxLength(20)
.Matches('^[a-zA-Z0-9_]+$')
.Validate(Username);
if not ValidationResult.IsValid then
ShowMessage(ValidationResult.ErrorMessage);
end;
// Example 2: Validate age
var
Age: Integer;
ValidationResult: TDFValidationResult;
begin
Age := 15;
ValidationResult := TDFValidate.Integer
.Min(18)
.Max(120)
.Validate(Age);
if not ValidationResult.IsValid then
ShowMessage(ValidationResult.ErrorMessage); // Will show error since age is under 18
end;
// Example 3: Validate email
var
Email: string;
ValidationResult: TDFValidationResult;
begin
Email := 'user@example.com';
ValidationResult := TDFValidate.Email
.Required
.Validate(Email);
if not ValidationResult.IsValid then
ShowMessage(ValidationResult.ErrorMessage);
end;Available Validators
String Validator
Required()- Makes the string required (non-empty)MinLength(n)- Sets minimum string lengthMaxLength(n)- Sets maximum string lengthMatches(pattern)- Validates string against a regular expression pattern
Integer Validator
Min(n)- Sets minimum valueMax(n)- Sets maximum value
Date Validator
After(date)- Date must be after specified dateBefore(date)- Date must be before specified date
Email Validator
- Pre-configured string validator with email pattern
Creating Custom Validators
You can easily extend the library with your own validators:
type
TPhoneValidator = class(TDFValidator<string>)
private
FCountryCode: string;
public
constructor Create;
function Validate(const Value: string): TDFValidationResult; override;
function ForCountry(const ACountryCode: string): TPhoneValidator;
end;License
MIT License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.

