Download the PHP package ongom/php-validator without Composer
On this page you can find all versions of the php package ongom/php-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-validator
๐ PHPValidator
A flexible PHP validation class for validating strings, numbers, and files. It supports both static chaining and method chaining for clear and readable validation rules.
โ Available Static Methods
the name spce id use PHPValidator\Validate
-Initialize validation for a string.
-Initialize validation for a number (int or float).
-Initialize validation for an uploaded file. is the name of the . can be or a custom file array (e.g. from an API).
๐ค String Validation Methods
| Method | Description |
|---|---|
->min_length($len) |
Requires a minimum number of characters. |
->max_length($len) |
Requires a maximum number of characters. |
->uppercase() |
Requires at least one uppercase character. |
->lowercase() |
Requires at least one lowercase character. |
->has_number() |
Requires at least one numeric digit. |
->special_character() |
Requires at least one special character (non-alphanumeric). |
->email() |
Checks if the string is a valid email address. |
->url() |
Checks if the string is a valid URL. |
๐ข Number Validation Methods
| Method | Description |
|---|---|
->min($value) |
Minimum numeric value allowed. |
->max($value) |
Maximum numeric value allowed. |
->integer() |
Must be an integer. |
->float() |
Must be a float (or an integer is also accepted). |
๐๏ธ File Validation Methods
Use after .
| Method | Description |
|---|---|
->min_size($kb) |
Minimum size in kilobytes (KB). |
->max_size($kb) |
Maximum size in kilobytes (KB). |
->allowed_extension($exts) |
Allowed file extensions (string or array). |
->allowed_mime($mimes) |
Allowed MIME types (string or array). |
๐ง Custom Validation
Run any custom logic. If it fails, the provided error message is returned.
Example:
๐ฆ Final Step
Executes all validation rules and returns an array of error messages.
๐งช Examples
Validate String
Validate Number
Validate File Upload
๐งผ Notes
always returns an array. If valid, it will be an empty array.
File size is automatically handled in kilobytes.
You can extend this class easily with more rules or by subclassing.
Let me know if you'd like a version of this in a .md file or integrated into a documentation tool.