https://github.com/h2lsoft/validator
A library of validators values in multilanguage with CSRF protection
https://github.com/h2lsoft/validator
csrf csrf-protection data form php validator
Last synced: 5 months ago
JSON representation
A library of validators values in multilanguage with CSRF protection
- Host: GitHub
- URL: https://github.com/h2lsoft/validator
- Owner: h2lsoft
- License: mit
- Created: 2020-04-28T10:16:34.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-07-04T15:52:41.000Z (almost 2 years ago)
- Last Synced: 2025-07-04T09:47:06.002Z (12 months ago)
- Topics: csrf, csrf-protection, data, form, php, validator
- Language: PHP
- Homepage:
- Size: 85 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Validator
A library for string validators values in multilanguage.
[](https://badge.fury.io/gh/h2lsoft%2Fvalidator)
## Installation
Install directly via [Composer](https://getcomposer.org):
```bash
$ composer require h2lsoft/validator
```
## Basic Usage
```php
// simulate POST
$_POST['name'] = 'the king !';
$_POST['email'] = 'fa@email';
$_POST['zip_code'] = 'a2345';
$_POST['choices'] = ['apple'];
$_POST['job'] = 'webdesigner';
$_POST['days'] = '-50';
$_POST['date'] = '31/20/2020';
$_POST['datetime'] = '31/20/2020 12:00';
$_POST['website'] = 'text.com';
$_POST['regex_test'] = 'abcdef';
$_POST['conditions'] = 0;
// rules
$validator = new \h2lsoft\Data\Validator('en'); // `en` by default but you can change it
$validator->input('name')->required()->alpha(' '); // space allowed
$validator->input('email', "email address")->required()->email();
$validator->input('zip_code', 'zip code')->required()->mask('99999');
$validator->input('choices')->required()->multiple()->in(['banana', 'pear'])->minLength(2);
$validator->input('job')->required()->equal('CEO');
$validator->input('days')->required()->integer()->between(1, 60);
$validator->input('date')->date('m/d/Y');
$validator->input('datetime')->required()->datetime('m/d/Y H:i');
$validator->input('website')->url(FILTER_FLAG_PATH_REQUIRED);
$validator->input('regex_test')->regex("/^x/i", "`[FIELD]` must start by x");
$validator->input('conditions')->required()->accepted();
if($validator->fails())
{
print_r($validator->result());
}
else
{
die("No error detected");
}
```
## Rules
### Strings
* required
* email
* mask
* in
* notIn
* integer
* float
* min
* max
* between
* length
* minLength
* maxLength
* equal
* accepted
* url
* alpha
* alphaNumeric
* date
* datetime
* regex
* ip
* sameAs
* requiredIf
### Array (checkboxes, select multiple)
* multiple
* between
* min
* max
### Files
* fileRequired
* fileMaxSize
* fileExtension
* fileMime
* fileImage
* fileImageBase64
* fileImageWidth
* fileImageHeight
## Customisation
* addLocalMessages
* setInputNames (array)
* setInputName
* addError (custom error)
**More information see examples directory**
## License
MIT. See full [license](LICENSE).