Download the PHP package julienlinard/php-validator without Composer
On this page you can find all versions of the php package julienlinard/php-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download julienlinard/php-validator
More information about julienlinard/php-validator
Files in julienlinard/php-validator
Package php-validator
Short Description Système de validation avancé pour PHP 8+ avec règles personnalisées, messages multilingues, validation conditionnelle et sanitization
License MIT
Homepage https://github.com/julien-lin/php-validator
Informations about the package php-validator
PHP Validator
🇬🇧 Read in English
💝 Support the project
If this package is useful to you, consider becoming a sponsor to support the development and maintenance of this open source project.
A modern and advanced validation system for PHP 8+ with custom rules, multilingual messages, conditional validation, and sanitization.
🚀 Installation
Requirements: PHP 8.0 or higher
⚡ Quick Start
Basic Usage
📋 Features
- ✅ Built-in Rules: 30+ rules including required, email, min, max, numeric, url, in, pattern, date, boolean, between, file, image, size, alpha, alpha_num, alpha_dash, confirmed, ip, ipv4, ipv6, json, uuid, accepted, filled, before, after, different, same
- ✅ Custom Rules: Easy to create and register custom validation rules
- ✅ Multilingual Messages: Support for custom error messages
- ✅ Sanitization: Automatic HTML escaping and trimming
- ✅ Conditional Validation: Skip validation for empty values (except required)
- ✅ Flexible Rules: String format (
required|email|min:5) or array format - ✅ Validation Result: Rich result object with error handling
📖 Documentation
Available Rules
Required
Validates that a field is not empty.
Validates that a field contains a valid email address.
Min / Max
Validates the minimum/maximum length of a string or value.
Numeric
Validates that a value is numeric.
URL
Validates that a field contains a valid URL.
In
Validates that a value is in a list of allowed values.
Pattern
Validates that a value matches a regex pattern.
Date
Validates that a field contains a valid date.
Boolean
Validates that a field is a boolean value. Accepts: true, false, 1, 0, "1", "0", "true", "false", "yes", "no", "on", "off".
Between
Validates that a value is between two numbers (for numeric) or has a length between two values (for strings).
File
Validates that a field is a valid uploaded file.
Image
Validates that a field is a valid image file. Automatically checks MIME type and uses getimagesize() to ensure it's a real image.
Size
Validates that a field has an exact size (for files: bytes, for strings: characters, for numbers: exact value).
Alpha
Validates that a field contains only letters (including accented characters).
Alpha Num
Validates that a field contains only letters and numbers.
Alpha Dash
Validates that a field contains only letters, numbers, dashes and underscores.
Confirmed
Validates that a field has a matching confirmation field (e.g., password_confirmation).
IP Address
Validates that a field is a valid IP address.
JSON
Validates that a field contains a valid JSON string.
UUID
Validates that a field is a valid UUID (v1-v5).
Accepted
Validates that a field is accepted (yes, on, 1, true). Useful for checkboxes and terms acceptance.
Filled
Validates that a field has a value when present (different from required - allows null if field is not present).
Before / After
Validates that a date field is before or after another date.
Different / Same
Validates that a field is different from or same as another field.
Multilingual Support
The validator supports multiple languages (French, English, Spanish) out of the box.
Supported locales:
fr- French (default)en- Englishes- Spanish
Custom Messages
You can customize error messages for specific fields and rules.
Sanitization
By default, the validator automatically sanitizes input data (trims strings, escapes HTML).
Custom Rules
You can create and register custom validation rules.
Integration with core-php
This package integrates seamlessly with core-php Forms.
📚 API Reference
Validator
validate(array $data, array $rules): ValidationResult
Validates data against rules.
setCustomMessages(array $messages): self
Sets custom error messages.
setSanitize(bool $sanitize): self
Enables or disables automatic sanitization.
registerRule(RuleInterface $rule): self
Registers a custom validation rule.
ValidationResult
isValid(): bool
Checks if validation passed.
hasErrors(): bool
Checks if validation failed.
getErrors(): array
Gets all errors grouped by field.
getFieldErrors(string $field): array
Gets errors for a specific field.
getFirstError(string $field): ?string
Gets the first error for a field.
getValidated(): array
Gets all validated and sanitized data.
getValidatedValue(string $field, mixed $default = null): mixed
Gets a validated value for a specific field.
📝 License
MIT License - See the LICENSE file for more details.
🤝 Contributing
Contributions are welcome! Feel free to open an issue or a pull request.
💝 Support
If this package is useful to you, consider becoming a sponsor to support the development and maintenance of this open source project.
Developed with ❤️ by Julien Linard