dev-master
9999999-devPHP validation library
MIT
The Requires
- php ^7.0
The Development Requires
by Svilen Popov
dev-develop
dev-developPHP validation library
MIT
The Requires
- php ^7.0
The Development Requires
by Svilen Popov
PHP validation library
Simple and lightweight standalone PHP library for validating data., (*2)
<?php use SGP\Validation\Validator; $input = [ 'name' => 'Svilen Popov', 'comment' => 'This a comment', 'users' => [ [ 'age' => 20, 'username' => 'username1' ], [ 'age' => 16, 'username' => 'username2' ] ] ]; $rules = [ 'name' => 'required', 'comment' => 'required|min:20', 'users.*.age' => 'required|min:18' ]; $messages = [ 'comment.min' => 'Your comment should have at least 20 chars.' ]; $validator = Validator::make($input, $rules, $messages); $errors = $validator->errors()->all(); foreach ($errors as $error) { echo $error . PHP_EOL; }
and the above example will output:, (*3)
Your comment should have at least 20 chars. The users.1.age minimum is 18
Alpha | Integer |
---|---|
Alpha-Numeric | Max |
Boolean | Min |
Date after | Numeric |
Date before | Required |
Date |
Checks if the value contains only alphabetic characters., (*4)
'field' => 'alpha'
Checks if the valuecontains only alpha-numeric characters., (*5)
'field' => 'alpha_num'
Checks if the value is able to be cast as a boolean. Accepted input are true
, false
, 1
, 0
, "1"
, and "0"
., (*6)
'field' => 'boolean'
Checks if the value is a valid date and is after a given date., (*7)
'field' => 'date_after:2017-01-01'
Checks if the value is a valid date and is before a given date., (*8)
'field' => 'date_before:2017-01-01'
Checks if the value is a date/time string in the input format., (*9)
'field' => 'date'
Checks if the value is an integer., (*10)
'field' => 'int'
Checks if the value is less than given size. The rule works for strings, numerics and arrays., (*11)
'field' => 'max:20'
Checks if the value is greater than given size. The rule works for strings, numerics and arrays., (*12)
'field' => 'max:20'
Checks if the value is numeric., (*13)
'field' => 'numeric'
Checks if the value is not empty or null., (*14)
'field' => 'required'
PHP validation library
MIT
PHP validation library
MIT