A validator class to validate any type of input against any type of validation.
// initate the Validator with inputs and rules
$validator = Validator::make($inputs, $rules);
// test if validator pass all the tests
if($validator->fail()) {
// return with $validator->errors, an array of all error messages
}
else {
// do your stuff
}
$inputs
must be an array of all your input and $rules
must be an array of all the rules :
$rules = array(
'name' => array('required'),
'email' => array('required', 'email'),
'age' => array('integer')
)
Check if the input is empty
array('input' => array('required'))
Check if the input is empty if an other input has a conditionnal value
array('input' => array('requiredIf:other_input,conditionnal_value'))
Check if the input is empty if an other input is not empty
array('input' => array('requiredWith:other_input'))
Check if the input is empty if an other input is empty
array('input' => array('requiredWithout:other_input'))
Check if the input is integer
array('input' => array('integer'))
Check if the input is numeric
array('input' => array('numeric'))
Check if the input is a date
array('input' => array('date'))
Check if the input is different from compared values
array('input' => array('different:value_1,value_2,value_n'))
Check if the input match an email
array('input' => array('email'))
Check if the input match a canadian postal code
array('input' => array('postalCode'))
Check if the input match an american phone number
array('input' => array('phoneNumber'))
Check if the input is between a minimum and a maximum
array('input' => array('between:minimum,maximum'))
You can input
- string : test string length
- number : test number size
- file : test file size in kilobytes
Check if the input is under a minimum
array('input' => array('minimum:integer'))
You can input
- string : test string length
- number : test number size
- file : test file size in kilobytes
Check if the input is over a maximum
array('input' => array('maximum:integer'))
You can input
- string : test string length
- number : test number size
- file : test file size in kilobytes
Check if the input has the exact size
array('input' => array('size:integer'))
You can input
- string : test string length
- number : test number size
- file : test file size in kilobytes
Check if the input has the exact length
array('input' => array('length:integer'))
Check if the input match an URL
array('input' => array('url'));
Check if the input match an URL that is valid
array('input' => array('validUrl'));
Check if confirmed value is the same
array('input' => array('same:input_name'));
Check if the input_confirmation value is the same then the input
array('input' => array('confirmed'));