Package Data | |
---|---|
Maintainer Username: | Elimentz |
Maintainer Contact: | jan.oris@ixudra.be (Jan Oris) |
Package Create Date: | 2014-04-06 |
Package Last Update: | 2021-12-09 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-14 15:02:30 |
Package Statistics | |
---|---|
Total Downloads: | 1,484 |
Monthly Downloads: | 11 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Custom PHP validation library - developed by Ixudra.
This package provides a wide variety of validation rules for PHP web applications. These rules can be used to easily validate user input to make sure that it meets the requirements that you have set.
Please also note that this package is intended for, but not exclusive to the Laravel framework. This basically means that
most validation methods are universally usable in any PHP application but some make use of internal Laravel components
(e.g. see UserValidationTrait
). These methods will probably not work correctly unless you also include the used dependencies
in you application as well.
This package can be used by anyone at any given time, but keep in mind that it is optimized for my personal custom workflow. It may not suit your project perfectly and modifications may be in order.
Pull this package in through Composer.
{
"require": {
"ixudra/validation": "1.*"
}
}
To use this package with Laravel 4 or 5, you will have to extend the default validator class. Once this class is created, you can include the traits into the class to make use of the validation methods. Laravel will automatically pick up the validation rules and make them available to you. Note that you don't have to include all traits if you don't want to. All validation rules are completely independent, which allows for maximum customization.
use Ixudra\Validation\DateValidationTrait;
use Ixudra\Validation\TimeValidationTrait;
use Ixudra\Validation\ArrayValidationTrait;
use Ixudra\Validation\PasswordValidationTrait;
use Ixudra\Validation\CoordinateValidationTrait;
class CustomValidator extends \Illuminate\Validation\Validator {
use DateValidationTrait;
use TimeValidationTrait;
use ArrayValidationTrait;
use PasswordValidationTrait;
use CoordinateValidationTrait;
}
Next, you will need to add the following to your routes.php
to let Laravel know that you want to use your custom validator
class instead of the default one:
Validator::resolver(function($translator, $data, $rules, $messages)
{
return new CustomValidator($translator, $data, $rules, $messages);
});
Once this is done, you are all set to go. You can now include the custom validation rules in the same way you use the default rules that Laravel already provides to you:
$attributes = array(
'att1' => 'john.doe@gmail.com',
'att2' => 0,
'att3' => date('Y-m-d', strtotime('next week'))
);
$rules = array(
'att1' => 'required|email',
'att2' => 'required|truthy',
'att3' => 'required|future'
);
$validator = Validator::make( $attributes, $rules );
$validator->fails();
true
if an array contains an entry where the value is true
true
if the value contains a date which is set in the pasttrue
if the value contains a date which is set in the future (not including today)true
if the value contains a date which is set less that three days in the pasttrue
if the value contains a date which is set in the future (including today)true
if the value a unique file name. This function expects the full path name of the file starting from the Laravel public/
directorytrue
is the value contains a valid JSON stringtrue
is the value larger than 0true
if the value is smaller than 0true
is the value contains a valid password (at least 6 characters long, at least one lowercase letter, at least one uppercase letter and at least one number)true
if the value contains the correct password for the authenticated user (does not try to re-authenticate the user)true
if the value contains an empty stringtrue
if the value contains a valid (Belgian) telephone numbertrue
if the value contains a valid timestamptrue
if the value contains a timestamp with the specified formattrue
if the value is either true
of false
true
if the value is true
true
if the value contains an email address which belongs to the authenticated usertrue
if the value contains an ID which belongs to the authenticated userHave fun!