Skip to content

Latest commit

 

History

History
249 lines (195 loc) · 4.8 KB

rules.md

File metadata and controls

249 lines (195 loc) · 4.8 KB

Rules list

Alpha

Checks if current string contains only letters

'firstname' => 'alpha' // in rules

'firstname' => 'Denys '       //true because of auto trim
'firstname' => 'Abra Cadabra' //false
'firstname' => ''             //true, because not required
'firstname' => ' '            //false, because empty value

Between

Checks if value is between for string length and number value

'randNum'   => 'between:1,50|numeric' // for numeric range
'name'      => 'between:3,18'         // for string length

'randNum' => '1'  //true
'randNum' => '50' //true
'randNum' => '51' //false

'name' => 'Den' //true
'name' => 'DK'  //false

Boolean

Applies only true or false values

'randNum' => 'boolean' // in rules

'randNum' => 'true'  //true
'randNum' => 'false' //true
'randNum' => '123'   //false

Date and Time Format

Applies if user value matches datetime pattern

'yearHours' => 'dateFormat:(Y H)' // in rules

'yearHours' => '2012 23'  //true
'yearHours' => '2012-23'  //false
'yearHours' => '1888 00'  //true

Email

Matches email address

'email' => 'email' // in rules

'email' => '[email protected]'      //true
'email' => 'test-failed @su.re'  //false

<a name="equals"></a>```
### Equals
The field equals to value
```php
'secretCode' => 'equals:mmx' // in rules

'secretCode' => 'mmx'  //true
'secretCode' => 'lol'  //false

Json

Matches string is Json

'response' => 'json'  // in rules

'response' => '[{}]'            //true
'response' => '[(\/)O_o{\/}]'   //false
'response' => '{"require": {"php": ">=5.4"} }' //true

In

Checks if value exists in array

'shop' => 'in:Metro, ATB, Silpo'  // in rules

'shop' => 'Metro'     //true
'shop' => 'McDonalds' //false

Image

If file is image, it works)

'myPhoto' => 'image'  // in rules

Ip

Check ipv4 or ipv6 for validness

'ipAddr' => 'ip'  // in rules

'ipAddr' => '77.132.104.66'        //true
'ipAddr' => '77.132.104~66'        //false
'ipAddr' => '2607:f0d0:1002:51::4' //true

Max

Checking for string length or value of number less than param

'str' => 'max:5'         // string length
'num' => 'max:5|numeric' // for numeric values

'str' => 'hello'  //true
'str' => 'world!' //false

'num' => '3'      //true
'num' => '-100'   //true
'num' => '7'      //false

Min

Checking for string length or value of number less than param

'str' => 'min:2'         // string length
'num' => 'min:2|numeric' // for numeric values

'str' => 'hello'  //true
'str' => 'w'      //false

'num' => '2'      //true
'num' => '-100'   //false
'num' => '7'      //true

Not In

Checks if value not exists in array

'shop' => 'notIn:Metro, ATB, Silpo'  // in rules

'shop' => 'Metro'     //false
'shop' => 'McDonalds' //true

Numeric

Checks if value is number

'age' => 'numeric'  // in rules

'age' => '100'    //true
'age' => '100kb'  //false

Phone Mask

Checking if value matches phone mask

'phone' => 'phoneMask:(+38(###)###-##-##)', //define phone mask

'phone' => '+38(052)123-45-67'  //true
'phone' => '+38-052-123-45-67'  //false
'phone' => 'phone test fails'   //false

Required

Checks for field is required and not empty

'value' => 'required'  // in rules

'value' => 'yep' //true
'value' => ' '   //false
'value' => ''    //false

Same

Check if one field has same value with other

'password_repeat' => 'same:password'  // in rules

'password'        => '123'
'password_repeat' => '123' //true

'password'        => '321'
'password_repeat' => ''    //false

Size

Check if string is the same size

'keyCode' => 'required|size:3'

'keyCode' => 'yes' //true
'keyCode' => 'no'  //false

Url

Matches url pattern

'site' => 'url'  // in rules

'site' => 'http://mmx.com'             //true
'site' => 'https://mmx.com'            //true
'site' => 'mailto:[email protected]' //true
'site' => 'news:news.yahoo.com'        //true
'site' => 'mmx.com'                    //false
'site' => 'mmx'                        //false