2014-01-29 02:34:15 +01:00
|
|
|
Respect\Validation
|
2011-02-07 02:35:35 +01:00
|
|
|
==================
|
2013-01-22 22:08:38 +01:00
|
|
|
|
2015-01-24 04:49:31 +01:00
|
|
|
[![Build Status](https://img.shields.io/travis/Respect/Validation/master.svg?style=flat-square)](http://travis-ci.org/Respect/Validation)
|
|
|
|
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/Respect/Validation/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/Respect/Validation/?branch=master)
|
|
|
|
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/Respect/Validation/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/Respect/Validation/?branch=master)
|
|
|
|
[![Latest Stable Version](https://img.shields.io/packagist/v/respect/validation.svg?style=flat-square)](https://packagist.org/packages/respect/validation)
|
2015-01-07 16:50:00 +01:00
|
|
|
[![Total Downloads](https://img.shields.io/packagist/dt/respect/validation.svg?style=flat-square)](https://packagist.org/packages/respect/validation)
|
|
|
|
[![License](https://img.shields.io/packagist/l/respect/validation.svg?style=flat-square)](https://packagist.org/packages/respect/validation)
|
2014-01-29 02:34:15 +01:00
|
|
|
|
2014-02-16 05:22:02 +01:00
|
|
|
[The most awesome validation engine ever created for PHP.](http://bit.ly/1a1oeQv)
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2015-01-11 22:54:38 +01:00
|
|
|
- Complex rules made simple: `v::numeric()->positive()->between(1, 256)->validate($myNumber)`.
|
|
|
|
- [Granularity control](https://github.com/Respect/Validation#validation-methods) for advanced reporting.
|
2014-02-16 05:22:02 +01:00
|
|
|
- >80 (fully tested) validators.
|
2015-01-11 22:54:38 +01:00
|
|
|
- [A concrete API](https://gist.github.com/alganet/b66bc8281672ca3d3b42) for non fluent usage.
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2011-02-08 23:10:58 +01:00
|
|
|
Installation
|
2012-04-10 03:46:28 +02:00
|
|
|
------------
|
2011-02-08 23:10:58 +01:00
|
|
|
|
2015-01-06 18:08:01 +01:00
|
|
|
The package is available on [Packagist](http://packagist.org/packages/respect/validation).
|
|
|
|
Autoloading is [PSR-4](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md) compatible.
|
|
|
|
|
|
|
|
```shell
|
|
|
|
composer require respect/validation
|
|
|
|
```
|
2011-02-08 23:10:58 +01:00
|
|
|
|
2011-02-07 15:46:08 +01:00
|
|
|
Feature Guide
|
2012-04-10 03:46:28 +02:00
|
|
|
-------------
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2012-04-10 04:14:20 +02:00
|
|
|
### Namespace Import
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2011-02-07 15:46:08 +01:00
|
|
|
Respect\Validation is namespaced, but you can make your life easier by importing
|
|
|
|
a single class into your context:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
use Respect\Validation\Validator as v;
|
|
|
|
```
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2012-04-10 04:14:20 +02:00
|
|
|
### Simple Validation
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2011-02-07 15:46:08 +01:00
|
|
|
The Hello World validator is something like this:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
$number = 123;
|
|
|
|
v::numeric()->validate($number); //true
|
|
|
|
```
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2012-04-10 04:14:20 +02:00
|
|
|
### Chained Validation
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
It is possible to use validators in a chain. Sample below validates a string
|
2013-02-26 00:15:23 +01:00
|
|
|
containing numbers and letters, no whitespace and length between 1 and 15.
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
$usernameValidator = v::alnum()->noWhitespace()->length(1,15);
|
|
|
|
$usernameValidator->validate('alganet'); //true
|
|
|
|
```
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2012-04-10 04:14:20 +02:00
|
|
|
### Validating Object Attributes
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
Given this simple object:
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
$user = new stdClass;
|
|
|
|
$user->name = 'Alexandre';
|
|
|
|
$user->birthdate = '1987-07-01';
|
|
|
|
```
|
2011-02-07 15:22:30 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
Is possible to validate its attributes in a single chain:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
$userValidator = v::attribute('name', v::string()->length(1,32))
|
|
|
|
->attribute('birthdate', v::date()->minimumAge(18));
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
$userValidator->validate($user); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validating array keys is also possible using `v::key()`
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
Note that we used `v::string()` and `v::date()` in the beginning of the validator.
|
|
|
|
Although is not mandatory, it is a good practice to use the type of the
|
|
|
|
validated object as the first node in the chain.
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2013-01-23 09:53:30 +01:00
|
|
|
### Input optional
|
|
|
|
|
|
|
|
All validators treat input as optional and will accept empty string input as valid,
|
2013-02-26 00:15:23 +01:00
|
|
|
unless otherwise stated in the documentation.
|
2013-01-23 09:53:30 +01:00
|
|
|
|
2014-04-09 10:05:15 +02:00
|
|
|
We use the `v:notEmpty()` validator prefixed to disallow empty input and effectively
|
2013-01-23 09:53:30 +01:00
|
|
|
define the field as mandatory as input will be required or validation will fail.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::string()->notEmpty()->validate(''); //false input required
|
|
|
|
```
|
2013-01-23 09:53:30 +01:00
|
|
|
|
2012-04-10 04:14:20 +02:00
|
|
|
### Negating Rules
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
You can use the `v::not()` to negate any rule:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::not(v::int())->validate(10); //false, input must not be integer
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-22 22:08:38 +01:00
|
|
|
### Validator Reuse
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Once created, you can reuse your validator anywhere. Remember $usernameValidator?
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
$usernameValidator->validate('respect'); //true
|
|
|
|
$usernameValidator->validate('alexandre gaigalas'); //false
|
|
|
|
$usernameValidator->validate('#$%'); //false
|
|
|
|
```
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2012-04-10 04:14:20 +02:00
|
|
|
### Informative Exceptions
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2013-02-26 00:15:23 +01:00
|
|
|
When something goes wrong, Validation can tell you exactly what's going on. For this,
|
2012-04-09 00:08:39 +02:00
|
|
|
we use the `assert()` method instead of `validate()`:
|
2011-02-07 15:22:30 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
try {
|
|
|
|
$usernameValidator->assert('really messed up screen#name');
|
2014-07-25 16:22:47 +02:00
|
|
|
} catch(DomainException $e) {
|
2014-04-12 16:59:10 +02:00
|
|
|
echo $e->getFullMessage();
|
|
|
|
}
|
|
|
|
```
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
The printed message is exactly this, as a text tree:
|
2011-02-07 15:22:30 +01:00
|
|
|
|
2011-02-08 23:10:58 +01:00
|
|
|
\-All of the 3 required rules must pass
|
2012-04-09 00:08:39 +02:00
|
|
|
|-"really messed up screen#name" must contain only letters (a-z) and digits (0-9)
|
2011-02-08 23:10:58 +01:00
|
|
|
|-"really messed up screen#name" must not contain whitespace
|
|
|
|
\-"really messed up screen#name" must have a length between 1 and 15
|
2011-02-07 15:22:30 +01:00
|
|
|
|
2012-04-10 04:14:20 +02:00
|
|
|
### Getting Messages
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
The text tree is fine, but unusable on a HTML form or something more custom. You can use
|
|
|
|
`findMessages()` for that:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
try {
|
|
|
|
$usernameValidator->assert('really messed up screen#name');
|
|
|
|
} catch(\InvalidArgumentException $e) {
|
|
|
|
var_dump($e->findMessages(array('alnum', 'length', 'noWhitespace')));
|
|
|
|
}
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
`findMessages()` returns an array with messages from the requested validators.
|
|
|
|
|
2012-04-10 04:14:20 +02:00
|
|
|
### Custom Messages
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Getting messages as an array is fine, but sometimes you need to customize them in order
|
|
|
|
to present them to the user. This is possible using the `findMessages()` method as well:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
$errors = $e->findMessages(array(
|
|
|
|
'alnum' => '{{name}} must contain only letters and digits',
|
|
|
|
'length' => '{{name}} must not have more than 15 chars',
|
|
|
|
'noWhitespace' => '{{name}} cannot contain spaces'
|
|
|
|
));
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
For all messages, the `{{name}}` and `{{input}}` variable is available for templates.
|
|
|
|
|
2012-04-10 04:14:20 +02:00
|
|
|
### Validator Name
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-22 22:08:38 +01:00
|
|
|
On `v::attribute()` and `v::key()`, `{{name}}` is the attribute/key name. For others,
|
2012-04-09 00:08:39 +02:00
|
|
|
is the same as the input. You can customize a validator name using:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::date('Y-m-d')->between('1980-02-02', 'now')->setName('Member Since');
|
|
|
|
```
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-10 04:14:20 +02:00
|
|
|
### Zend/Symfony Validators
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
It is also possible to reuse validators from other frameworks if they are installed:
|
2011-02-07 15:22:30 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
$hostnameValidator = v::zend('Hostname')->assert('google.com');
|
|
|
|
$timeValidator = v::sf('Time')->assert('22:00:01');
|
|
|
|
```
|
2011-02-07 15:22:30 +01:00
|
|
|
|
2012-04-10 04:14:20 +02:00
|
|
|
### Validation Methods
|
2011-02-07 15:22:30 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
We've seen `validate()` that returns true or false and `assert()` that throws a complete
|
|
|
|
validation report. There is also a `check()` method that returns an Exception
|
|
|
|
only with the first error found:
|
2011-02-07 15:22:30 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
try {
|
|
|
|
$usernameValidator->check('really messed up screen#name');
|
|
|
|
} catch(\InvalidArgumentException $e) {
|
|
|
|
echo $e->getMainMessage();
|
|
|
|
}
|
|
|
|
```
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
Message:
|
|
|
|
|
|
|
|
"really messed up screen#name" must contain only letters (a-z) and digits (0-9)
|
|
|
|
|
|
|
|
Reference
|
2012-04-10 03:46:28 +02:00
|
|
|
---------
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 04:14:20 +02:00
|
|
|
### Types
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::arr()](#varr)
|
|
|
|
* [v::bool()](#vbool)
|
|
|
|
* [v::date()](#vdate)
|
2015-01-22 17:47:55 +01:00
|
|
|
* [v::false()](#vfalse)
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::float()](#vfloat)
|
|
|
|
* [v::hexa()](#vhexa-deprecated) *(deprecated)*
|
|
|
|
* [v::instance()](#vinstanceinstancename)
|
|
|
|
* [v::int()](#vint)
|
|
|
|
* [v::nullValue()](#vnullvalue)
|
|
|
|
* [v::numeric()](#vnumeric)
|
|
|
|
* [v::object()](#vobject)
|
|
|
|
* [v::string()](#vstring)
|
2015-01-22 17:43:58 +01:00
|
|
|
* [v::true()](#vtrue)
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::xdigit()](#vxdigit)
|
2012-04-09 00:55:05 +02:00
|
|
|
|
2012-04-10 04:14:20 +02:00
|
|
|
### Generics
|
2012-04-09 00:55:05 +02:00
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::call()](#vcallcallable-callback)
|
|
|
|
* [v::callback()](#vcallbackcallable-callback)
|
2015-01-26 13:10:54 +01:00
|
|
|
* [v::filterVar()](#vfiltervarint-filter)
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::not()](#vnotv-negatedvalidator)
|
|
|
|
* [v::when()](#vwhenv-if-v-then-v-else)
|
|
|
|
* [v::alwaysValid()](#valwaysvalid)
|
|
|
|
* [v::alwaysInvalid()](#valwaysinvalid)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 04:14:20 +02:00
|
|
|
### Comparing Values
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::between()](#vbetweenstart-end)
|
|
|
|
* [v::equals()](#vequalsvalue)
|
2014-12-04 20:38:23 +01:00
|
|
|
* [v::max()](#vmaxmax)
|
|
|
|
* [v::min()](#vminmin)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 04:14:20 +02:00
|
|
|
### Numeric
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::between()](#vbetweenstart-end)
|
|
|
|
* [v::bool()](#vbool)
|
|
|
|
* [v::even()](#veven)
|
|
|
|
* [v::float()](#vfloat)
|
|
|
|
* [v::hexa()](#vhexa-deprecated) *(deprecated)*
|
|
|
|
* [v::int()](#vint)
|
|
|
|
* [v::multiple()](#vmultiplemultipleof)
|
|
|
|
* [v::negative()](#vnegative)
|
|
|
|
* [v::notEmpty()](#vnotempty)
|
|
|
|
* [v::numeric()](#vnumeric)
|
|
|
|
* [v::odd()](#vodd)
|
|
|
|
* [v::perfectSquare()](#vperfectsquare)
|
|
|
|
* [v::positive()](#vpositive)
|
|
|
|
* [v::primeNumber()](#vprimenumber)
|
|
|
|
* [v::roman()](#vroman)
|
|
|
|
* [v::xdigit()](#vxdigit)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-22 22:08:38 +01:00
|
|
|
### String
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::alnum()](#valnum)
|
|
|
|
* [v::alpha()](#valpha)
|
|
|
|
* [v::between()](#vbetweenstart-end)
|
|
|
|
* [v::charset()](#vcharset)
|
|
|
|
* [v::consonants()](#vconsonants-deprecated) *(deprecated)*
|
|
|
|
* [v::consonant()](#vconsonant)
|
|
|
|
* [v::contains()](#vcontainsvalue)
|
|
|
|
* [v::cntrl()](#vcntrl)
|
|
|
|
* [v::digits()](#vdigits-deprecated) *(deprecated)*
|
|
|
|
* [v::digit()](#vdigit)
|
|
|
|
* [v::endsWith()](#vendswithvalue)
|
|
|
|
* [v::in()](#vinhaystack)
|
|
|
|
* [v::graph()](#vgraph)
|
|
|
|
* [v::length()](#vlengthmin-max)
|
|
|
|
* [v::lowercase()](#vlowercase)
|
|
|
|
* [v::notEmpty()](#vnotempty)
|
|
|
|
* [v::noWhitespace()](#vnowhitespace)
|
|
|
|
* [v::prnt()](#vprnt)
|
|
|
|
* [v::punct()](#vpunct)
|
|
|
|
* [v::regex()](#vregexregex)
|
|
|
|
* [v::slug()](#vslug)
|
|
|
|
* [v::space()](#vspace)
|
|
|
|
* [v::startsWith()](#vstartswithvalue)
|
|
|
|
* [v::uppercase()](#vuppercase)
|
|
|
|
* [v::version()](#vversion)
|
|
|
|
* [v::vowels()](#vvowels-deprecated) *(deprecated)*
|
|
|
|
* [v::vowel()](#vvowel)
|
|
|
|
* [v::xdigit()](#vxdigit)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 04:14:20 +02:00
|
|
|
### Arrays
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::arr()](#varr)
|
|
|
|
* [v::contains()](#vcontainsvalue)
|
|
|
|
* [v::each()](#veachv-validatorforvalue)
|
|
|
|
* [v::endsWith()](#vendswithvalue)
|
|
|
|
* [v::in()](#vinhaystack)
|
|
|
|
* [v::key()](#vkeyname)
|
|
|
|
* [v::length()](#vlengthmin-max)
|
|
|
|
* [v::notEmpty()](#vnotempty)
|
|
|
|
* [v::startsWith()](#vstartswithvalue)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 04:14:20 +02:00
|
|
|
### Objects
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::attribute()](#vattributename)
|
|
|
|
* [v::instance()](#vinstanceinstancename)
|
|
|
|
* [v::length()](#vlengthmin-max)
|
2012-04-10 04:14:20 +02:00
|
|
|
|
|
|
|
### Date and Time
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::between()](#vbetweenstart-end)
|
|
|
|
* [v::date()](#vdate)
|
|
|
|
* [v::leapDate()](#vleapdateformat)
|
|
|
|
* [v::leapYear()](#vleapyear)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 04:14:20 +02:00
|
|
|
### Group Validators
|
2011-02-07 15:22:30 +01:00
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::allOf()](#vallofv1-v2-v3)
|
|
|
|
* [v::noneOf()](#vnoneofv1-v2-v3)
|
|
|
|
* [v::oneOf()](#voneofv1-v2-v3)
|
2011-02-07 15:22:30 +01:00
|
|
|
|
2012-05-24 17:13:48 +02:00
|
|
|
### Regional
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::tld()](#vtld)
|
|
|
|
* [v::countryCode()](#vcountrycode)
|
2015-01-16 20:15:44 +01:00
|
|
|
* [v::postalCode()](#vpostalcodestring-countrycode)
|
2012-05-24 17:13:48 +02:00
|
|
|
|
2013-02-05 00:55:19 +01:00
|
|
|
### Files
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::directory()](#vdirectory)
|
2014-08-28 05:34:17 +02:00
|
|
|
* [v::executable()](#vexecutable)
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::exists()](#vexists)
|
|
|
|
* [v::file()](#vfile)
|
|
|
|
* [v::readable()](#vreadable)
|
|
|
|
* [v::symbolicLink()](#vsymboliclink)
|
|
|
|
* [v::uploaded()](#vuploaded)
|
|
|
|
* [v::writable()](#vwritable)
|
2013-02-05 00:55:19 +01:00
|
|
|
|
2014-06-25 11:10:31 +02:00
|
|
|
### Banking
|
|
|
|
|
|
|
|
* [v::bank()](#vbankstring-countrycode)
|
|
|
|
* [v::bankAccount()](#vbankaccountstring-countrycode-string-bank)
|
|
|
|
* [v::bic()](#vbicstring-countrycode)
|
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
### Other
|
2011-03-31 00:06:59 +02:00
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::cnh()](#vcnh)
|
|
|
|
* [v::cnpj()](#vcnpj)
|
|
|
|
* [v::cpf()](#vcpf)
|
|
|
|
* [v::domain()](#vdomain)
|
|
|
|
* [v::email()](#vemail)
|
2014-07-16 10:02:26 +02:00
|
|
|
* [v::hexRgbColor()](#vhexrgbcolor)
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::ip()](#vip)
|
|
|
|
* [v::json()](#vjson)
|
|
|
|
* [v::macAddress()](#vmacaddress)
|
|
|
|
* [v::phone()](#vphone)
|
|
|
|
* [v::sf()](#vsfsfvalidator)
|
2015-01-27 13:25:20 +01:00
|
|
|
* [v::url()](#vurl)
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::zend()](#vzendzendvalidator)
|
|
|
|
* [v::nfeAccessKey()](#vnfeaccesskey)
|
2011-03-31 00:06:59 +02:00
|
|
|
|
2015-01-06 23:14:08 +01:00
|
|
|
### Yes/No
|
|
|
|
|
|
|
|
* [v::yes()](#vyesuselocale--false)
|
|
|
|
* [v::no()](#vnouselocale--false)
|
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
### Alphabetically
|
2011-04-29 21:00:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::allOf($v1, $v2, $v3...)
|
2011-03-31 00:06:59 +02:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
Will validate if all inner validators validates.
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::allOf(
|
|
|
|
v::int(),
|
|
|
|
v::positive()
|
|
|
|
)->validate(15); //true
|
|
|
|
```
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
This is similar to the chain (which is an allOf already), but
|
|
|
|
its syntax allows you to set custom names for every node:
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::allOf(
|
|
|
|
v::int()->setName('Account Number'),
|
|
|
|
v::positive()->setName('Higher Than Zero')
|
|
|
|
)->setName('Positive integer')
|
|
|
|
->validate(15); //true
|
|
|
|
```
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
See also:
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::oneOf()](#voneofv1-v2-v3) - Validates if at least one inner rule pass
|
|
|
|
* [v::noneOf()](#vnoneofv1-v2-v3) - Validates if no inner rules pass
|
|
|
|
* [v::when()](#vwhenv-if-v-then-v-else) - A Ternary validator
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::alnum()
|
|
|
|
#### v::alnum(string $additionalChars)
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2013-01-22 22:08:38 +01:00
|
|
|
Validates alphanumeric characters from a-Z and 0-9.
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::alnum()->validate('foo 123'); //true
|
|
|
|
```
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
A parameter for extra characters can be used:
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::alnum('-')->validate('foo - 123'); //true
|
|
|
|
```
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2013-01-22 22:08:38 +01:00
|
|
|
This validator allows whitespace, if you want to
|
2012-04-09 00:08:39 +02:00
|
|
|
remove them add `->noWhitespace()` to the chain:
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::alnum()->noWhitespace->validate('foo 123'); //false
|
|
|
|
```
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2013-01-23 09:53:30 +01:00
|
|
|
By default empty values are allowed, if you want
|
2012-04-09 00:08:39 +02:00
|
|
|
to invalidate them, add `->notEmpty()` to the chain:
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::alnum()->notEmpty()->validate(''); //false
|
|
|
|
```
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
You can restrict case using the `->lowercase()` and
|
|
|
|
`->uppercase()` validators:
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::alnum()->uppercase()->validate('aaa'); //false
|
|
|
|
```
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
Message template for this validator includes `{{additionalChars}}` as
|
|
|
|
the string of extra chars passed as the parameter.
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
See also:
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::alpha()](#valpha) - a-Z, empty or whitespace only
|
|
|
|
* [v::digit()](#vdigit) - 0-9, empty or whitespace only
|
|
|
|
* [v::consonant()](#vconsonant)
|
|
|
|
* [v::vowel()](#vvowel)
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::alpha()
|
|
|
|
#### v::alpha(string $additionalChars)
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
This is similar to v::alnum(), but it doesn't allow numbers. It also
|
|
|
|
accepts empty values and whitespace, so use `v::notEmpty()` and
|
|
|
|
`v::noWhitespace()` when appropriate.
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
See also:
|
2011-02-07 02:35:35 +01:00
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::alnum()](#valnum) - a-z0-9, empty or whitespace only
|
|
|
|
* [v::digit()](#vdigit) - 0-9, empty or whitespace only
|
|
|
|
* [v::consonant()](#vconsonant)
|
|
|
|
* [v::vowel()](#vvowel)
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::arr()
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
Validates if the input is an array or traversable object.
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::arr()->validate(array()); //true
|
|
|
|
v::arr()->validate(new ArrayObject); //true
|
|
|
|
```
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
See also:
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::each()](#veachv-validatorforvalue) - Validates each member of an array
|
|
|
|
* [v::key()](#vkeyname) - Validates a specific key of an array
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-05-24 17:13:48 +02:00
|
|
|
### v::alwaysValid
|
|
|
|
|
|
|
|
Always returns true.
|
|
|
|
|
|
|
|
### v::alwaysInvalid
|
|
|
|
|
|
|
|
Always return false.
|
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::attribute($name)
|
|
|
|
#### v::attribute($name, v $validator)
|
|
|
|
#### v::attribute($name, v $validator, boolean $mandatory=true)
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
Validates an object attribute.
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
$obj = new stdClass;
|
|
|
|
$obj->foo = 'bar';
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
v::attribute('foo')->validate($obj); //true
|
|
|
|
```
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
You can also validate the attribute itself:
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::attribute('foo', v::equals('bar'))->validate($obj); //true
|
|
|
|
```
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
Third parameter makes the attribute presence optional:
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::attribute('lorem', v::string(), false)->validate($obj); // true
|
|
|
|
```
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
The name of this validator is automatically set to the attribute name.
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
See also:
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::key()](#vkeyname) - Validates a specific key of an array
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-06-25 11:10:31 +02:00
|
|
|
#### v::bank(string $countryCode)
|
|
|
|
|
|
|
|
Validates a bank.
|
|
|
|
|
|
|
|
```php
|
|
|
|
v::bank("de")->validate("70169464"); //true
|
|
|
|
v::bank("de")->validate("12345"); //false
|
|
|
|
```
|
|
|
|
|
|
|
|
These country codes are supported:
|
|
|
|
|
2015-01-17 18:24:18 +01:00
|
|
|
* "de" (Germany) - You must add `"malkusch/bav": "~1.0"` to your `require` property on composer.json file.
|
2014-06-25 11:10:31 +02:00
|
|
|
|
|
|
|
See also
|
|
|
|
|
|
|
|
* [v::bankAccount()](#vbankaccountstring-countrycode-string-bank)
|
|
|
|
* [v::bic()](#vbicstring-countrycode)
|
|
|
|
|
|
|
|
#### v::bankAccount(string $countryCode, string $bank)
|
|
|
|
|
|
|
|
Validates a bank account for a given bank.
|
|
|
|
|
|
|
|
```php
|
|
|
|
v::bankAccount("de", "70169464")->validate("1112"); //true
|
|
|
|
v::bankAccount("de", "70169464")->validate("1234"); //false
|
|
|
|
```
|
|
|
|
|
|
|
|
These country codes are supported:
|
|
|
|
|
2015-01-17 18:24:18 +01:00
|
|
|
* "de" (Germany) - You must add `"malkusch/bav": "~1.0"` to your `require` property on composer.json file.
|
2014-06-25 11:10:31 +02:00
|
|
|
|
|
|
|
See also
|
|
|
|
|
|
|
|
* [v::bank()](#vbankstring-countrycode)
|
|
|
|
* [v::bic()](#vbicstring-countrycode)
|
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::between($start, $end)
|
|
|
|
#### v::between($start, $end, boolean $inclusive=false)
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
Validates ranges. Most simple example:
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::int()->between(10, 20)->validate(15); //true
|
|
|
|
```
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2013-01-22 22:08:38 +01:00
|
|
|
The type as the first validator in a chain is a good practice,
|
2012-04-09 00:08:39 +02:00
|
|
|
since between accepts many types:
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::string()->between('a', 'f')->validate('c'); //true
|
|
|
|
```
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
Also very powerful with dates:
|
2011-02-21 01:53:21 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::date()->between('2009-01-01', '2013-01-01')->validate('2010-01-01'); //true
|
|
|
|
```
|
2011-02-21 01:53:21 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
Date ranges accept strtotime values:
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::date()->between('yesterday', 'tomorrow')->validate('now'); //true
|
|
|
|
```
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
A third parameter may be passed to validate the passed values inclusive:
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::date()->between(10, 20, true)->validate(20); //true
|
|
|
|
```
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
Message template for this validator includes `{{minValue}}` and `{{maxValue}}`.
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
See also:
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::length()](#vlengthmin-max) - Validates the length of a input
|
2014-12-04 20:38:23 +01:00
|
|
|
* [v::min()](#vminmin)
|
|
|
|
* [v::max()](#vmaxmax)
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-06-25 11:10:31 +02:00
|
|
|
#### v::bic(string $countryCode)
|
|
|
|
|
|
|
|
Validates a BIC (Bank Identifier Code) for a given country.
|
|
|
|
|
|
|
|
```php
|
|
|
|
v::bic("de")->validate("VZVDDED1XXX"); //true
|
|
|
|
v::bic("de")->validate("VZVDDED1"); //true
|
|
|
|
```
|
|
|
|
|
|
|
|
Theses country codes are supported:
|
|
|
|
|
2015-01-17 18:24:18 +01:00
|
|
|
* "de" (Germany) - You must add `"malkusch/bav": "~1.0"` to your `require` property on composer.json file.
|
2014-06-25 11:10:31 +02:00
|
|
|
|
|
|
|
See also
|
|
|
|
|
|
|
|
* [v::bank()](#vbankstring-countrycode)
|
|
|
|
* [v::bankAccount()](#vbankaccountstring-countrycode-string-bank)
|
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::bool()
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
Validates if the input is a boolean value:
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::bool()->validate(true); //true
|
|
|
|
v::bool()->validate(false); //true
|
|
|
|
```
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::call(callable $callback)
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
This is a very low level validator. It calls a function, method or closure
|
|
|
|
for the input and then validates it. Consider the following variable:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
$url = 'http://www.google.com/search?q=respect.github.com'
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-22 22:08:38 +01:00
|
|
|
To validate every part of this URL we could use the native `parse_url`
|
2012-04-09 00:08:39 +02:00
|
|
|
function to break its parts:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
$parts = parse_url($url);
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
This function returns an array containing `scheme`, `host`, `path` and `query`.
|
|
|
|
We can validate them this way:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::arr()->key('scheme', v::startsWith('http'))
|
|
|
|
->key('host', v::domain())
|
|
|
|
->key('path', v::string())
|
|
|
|
->key('query', v::notEmpty());
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Using `v::call()` you can do this in a single chain:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::call(
|
|
|
|
'parse_url',
|
|
|
|
v::arr()->key('scheme', v::startsWith('http'))
|
|
|
|
->key('host', v::domain())
|
|
|
|
->key('path', v::string())
|
|
|
|
->key('query', v::notEmpty())
|
|
|
|
)->validate($url);
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
It is possible to call methods and closures as the first parameter:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::call(array($myObj, 'methodName'), v::int())->validate($myInput);
|
|
|
|
v::call(function($input) {}, v::int())->validate($myInput);
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::callback()](#vcallbackcallable-callback) - Similar, but a different workflow.
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::callback(callable $callback)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
This is a wildcard validator, it uses a function name, method or closure
|
|
|
|
to validate something:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::callback('is_int')->validate(10); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
(Please note that this is a sample, the `v::int()` validator is much better).
|
|
|
|
|
|
|
|
As in `v::call()`, you can pass a method or closure to it.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::call()](#vcallcallable-callback) - A more elaborated building block validator
|
2015-01-26 13:10:54 +01:00
|
|
|
* [v::filterVar()](#vfiltervarint-filter)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-12-07 02:31:24 +01:00
|
|
|
#### v::charset()
|
|
|
|
|
|
|
|
Validates if a string is in a specific charset.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::charset('ASCII', 'açúcar'); //false
|
|
|
|
v::charset('ASCII', 'sugar'); //true
|
|
|
|
v::charset(array('ISO-8859-1', 'EUC-JP'), '日本国'); // true
|
|
|
|
```
|
2012-12-07 02:31:24 +01:00
|
|
|
|
|
|
|
The array format is a logic OR, not AND.
|
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::cnpj()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates the Brazillian CNPJ number. Ignores non-digit chars, so
|
2013-01-22 22:07:57 +01:00
|
|
|
use `->digit()` if needed.
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::cpf()](#vcpf) - Validates the Brazillian CPF number.
|
|
|
|
* [v::cnh()](#vcnh) - Validates the Brazillian driver's license.
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-11-12 03:14:38 +01:00
|
|
|
#### v::nfeAccessKey()
|
|
|
|
|
|
|
|
Validates the access key of the Brazilian electronic invoice (NFe).
|
|
|
|
|
2013-01-22 22:39:41 +01:00
|
|
|
#### v::consonants() *(deprecated)*
|
|
|
|
|
|
|
|
Validates strings that contain only consonants. It's now deprecated, consonant should be used
|
|
|
|
instead.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::consonant()](#vconsonant)
|
2013-01-22 22:39:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
#### v::consonant()
|
|
|
|
#### v::consonant(string $additionalChars)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Similar to `v::alnum()`. Validates strings that contain only consonants:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::consonant()->validate('xkcd'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::alnum()](#valnum) - a-z0-9, empty or whitespace only
|
|
|
|
* [v::digit()](#vdigit) - 0-9, empty or whitespace only
|
|
|
|
* [v::alpha()](#valpha) - a-Z, empty or whitespace only
|
|
|
|
* [v::vowel()](#vvowel)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::contains($value)
|
|
|
|
#### v::contains($value, boolean $identical=false)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
For strings:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::contains('ipsum')->validate('lorem ipsum'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
For arrays:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::contains('ipsum')->validate(array('ipsum', 'lorem')); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
A second parameter may be passed for identical comparison instead
|
|
|
|
of equal comparison.
|
|
|
|
|
|
|
|
Message template for this validator includes `{{containsValue}}`.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::startsWith()](#vstartswithvalue)
|
|
|
|
* [v::endsWith()](#vendswithvalue)
|
|
|
|
* [v::in()](#vinhaystack)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-23 00:10:33 +01:00
|
|
|
#### v::cntrl
|
|
|
|
#### v::cntrl(string $additionalChars)
|
2013-01-21 16:44:49 +01:00
|
|
|
|
|
|
|
This is similar to `v::alnum()`, but only accepts control characters:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::cntrl()->validate("\n\r\t"); //true
|
|
|
|
```
|
2013-01-21 16:44:49 +01:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::alnum()](#valnum) - a-z0-9, empty or whitespace only
|
|
|
|
* [v::prnt()](#vprnt) - all printable characters
|
|
|
|
* [v::space()](#vspace) - empty or whitespace only
|
2013-01-21 16:44:49 +01:00
|
|
|
|
|
|
|
#### v::countryCode
|
|
|
|
|
|
|
|
Validates an ISO country code like US or BR.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::countryCode('BR'); //true
|
|
|
|
```
|
2013-01-21 16:44:49 +01:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::tld()](#vtld) - Validates a top level domain
|
2013-01-21 16:44:49 +01:00
|
|
|
|
|
|
|
#### v::cnh()
|
|
|
|
|
|
|
|
Validates a Brazillian driver's license.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::cnh()->validate('02650306461');
|
|
|
|
```
|
2013-01-21 16:44:49 +01:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::cnpj()](#vcnpj)
|
|
|
|
* [v::cpf()](#vcpf)
|
2013-01-21 16:44:49 +01:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::cpf()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates a Brazillian CPF number.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::cpf()->validate('44455566820');
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
It ignores any non-digit char:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::cpf()->validate('444.555.668-20');
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-22 22:07:57 +01:00
|
|
|
If you need to validate digits only, add `->digit()` to
|
2012-04-09 00:08:39 +02:00
|
|
|
the chain:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::digit()->cpf()->validate('44455566820');
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::cnpj()](#vcnpj)
|
|
|
|
* [v::cnh()](#vcnh)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::creditCard()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-22 22:08:38 +01:00
|
|
|
Validates a credit card number.
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::creditCard()->validate($myCredCardNumber);
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-22 22:07:57 +01:00
|
|
|
It ignores any non-digit chars, so use `->digit()` when appropriate.
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::digit()->creditCard()->validate($myCredCardNumber);
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::date()
|
|
|
|
#### v::date($format)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates if input is a date:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::date()->validate('2009-01-01'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Also accepts strtotime values:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::date()->validate('now'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
And DateTime instances:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::date()->validate(new DateTime); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
You can pass a format when validating strings:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::date('Y-m-d')->validate('01-01-2009'); //false
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Format has no effect when validating DateTime instances.
|
|
|
|
|
|
|
|
Message template for this validator includes `{{format}}`.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::between()](#vbetweenstart-end)
|
|
|
|
* [v::minimumAge()](#vminimumageage)
|
|
|
|
* [v::leapDate()](#vleapdateformat)
|
|
|
|
* [v::leapYear()](#vleapyear)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-22 22:07:57 +01:00
|
|
|
#### v::digits() *(deprecated)*
|
|
|
|
|
|
|
|
Validates 0-9, empty or whitespace only. It's now deprecated, digit should be used
|
|
|
|
instead.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::digit()](#vdigit)
|
2013-01-22 22:07:57 +01:00
|
|
|
|
|
|
|
#### v::digit()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
This is similar to v::alnum(), but it doesn't allow a-Z. It also
|
|
|
|
accepts empty values and whitespace, so use `v::notEmpty()` and
|
|
|
|
`v::noWhitespace()` when appropriate.
|
|
|
|
|
2013-01-22 22:07:57 +01:00
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::alnum()](#valnum) - a-z0-9, empty or whitespace only
|
|
|
|
* [v::alpha()](#valpha) - a-Z, empty or whitespace only
|
|
|
|
* [v::vowel()](#vvowel)
|
|
|
|
* [v::consonant()](#vconsonant)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::domain()
|
2013-09-01 17:16:05 +02:00
|
|
|
#### v::domain($checkTLD=true)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-22 22:08:38 +01:00
|
|
|
Validates domain names.
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::domain()->validate('google.com');
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-09-01 17:16:05 +02:00
|
|
|
You can skip *top level domain* (TLD) checks to validate internal
|
|
|
|
domain names:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::domain(false)->validate('dev.machine.local');
|
|
|
|
```
|
2013-09-01 17:16:05 +02:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
This is a composite validator, it validates several rules
|
|
|
|
internally:
|
|
|
|
|
2014-12-14 00:56:50 +01:00
|
|
|
* If input is an IP address, it fails.
|
2013-09-01 17:16:05 +02:00
|
|
|
* If input contains whitespace, it fails.
|
2014-12-14 00:56:50 +01:00
|
|
|
* If input does not contain any dots, it fails.
|
2013-09-01 17:16:05 +02:00
|
|
|
* If input has less than two parts, it fails.
|
|
|
|
* Input must end with a top-level-domain to pass (if not skipped).
|
|
|
|
* Each part must be alphanumeric and not start with an hyphen.
|
|
|
|
* [PunnyCode][] is accepted for [Internationalizing Domain Names in Applications][IDNA].
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Messages for this validator will reflect rules above.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::tld()](#vtld)
|
|
|
|
* [v::ip()](#vip)
|
2013-01-22 22:08:38 +01:00
|
|
|
|
2012-04-20 06:52:32 +02:00
|
|
|
#### v::directory()
|
|
|
|
|
|
|
|
Validates directories.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::directory()->validate(__DIR__); //true
|
|
|
|
v::directory()->validate(__FILE__); //false
|
|
|
|
```
|
2012-04-20 06:52:32 +02:00
|
|
|
|
2012-04-20 06:54:13 +02:00
|
|
|
This validator will consider SplFileInfo instances, so you can do something like:
|
2012-04-20 06:52:32 +02:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::directory()->validate(new \SplFileInfo($directory));
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-11 09:34:26 +01:00
|
|
|
See also
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::exists()](#vexists)
|
|
|
|
* [v::file()](#vfile)
|
2013-01-11 09:34:26 +01:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::each(v $validatorForValue)
|
|
|
|
#### v::each(null, v $validatorForKey)
|
|
|
|
#### v::each(v $validatorForValue, v $validatorForKey)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Iterates over an array or Iterator and validates the value or key
|
|
|
|
of each entry:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
$releaseDates = array(
|
|
|
|
'validation' => '2010-01-01',
|
|
|
|
'template' => '2011-01-01',
|
|
|
|
'relational' => '2011-02-05',
|
|
|
|
);
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
v::arr()->each(v::date())->validate($releaseDates); //true
|
|
|
|
v::arr()->each(v::date(), v::string()->lowercase())->validate($releaseDates); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Using `arr()` before `each()` is a best practice.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::key()](#vkeyname)
|
|
|
|
* [v::arr()](#varr)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::email()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates an email address.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::email()->validate('alexandre@gaigalas.net'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-08-28 05:34:17 +02:00
|
|
|
#### v::executable()
|
|
|
|
|
|
|
|
Validates if a file is an executable.
|
|
|
|
|
|
|
|
```php
|
|
|
|
v::email()->executable('script.sh'); //true
|
|
|
|
```
|
|
|
|
|
|
|
|
See also
|
|
|
|
|
|
|
|
* [v::readable()](#vreadable)
|
|
|
|
* [v::writable()](#vwritable)
|
|
|
|
|
2013-01-11 09:34:26 +01:00
|
|
|
#### v::exists()
|
|
|
|
|
|
|
|
Validates files or directories.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::exists()->validate(__FILE__); //true
|
|
|
|
v::exists()->validate(__DIR__); //true
|
|
|
|
```
|
2013-01-11 09:34:26 +01:00
|
|
|
|
|
|
|
This validator will consider SplFileInfo instances, so you can do something like:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::exists()->validate(new \SplFileInfo($file));
|
|
|
|
```
|
2013-01-11 09:34:26 +01:00
|
|
|
|
|
|
|
See also
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::directory()](#vdirectory)
|
|
|
|
* [v::file()](#vfile)
|
2013-01-11 09:34:26 +01:00
|
|
|
|
2015-01-22 17:47:55 +01:00
|
|
|
#### v::false()
|
|
|
|
|
|
|
|
Validates if a value is considered as `false`.
|
|
|
|
|
|
|
|
```php
|
|
|
|
v::false()->validate(false); //true
|
|
|
|
v::false()->validate(0); //true
|
|
|
|
v::false()->validate('0'); //true
|
|
|
|
v::false()->validate('false'); //true
|
|
|
|
v::false()->validate('off'); //true
|
|
|
|
v::false()->validate('no'); //true
|
|
|
|
```
|
|
|
|
|
|
|
|
See also
|
|
|
|
|
|
|
|
* [v::true()](#vtrue)
|
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::endsWith($value)
|
|
|
|
#### v::endsWith($value, boolean $identical=false)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
This validator is similar to `v::contains()`, but validates
|
|
|
|
only if the value is at the end of the input.
|
|
|
|
|
|
|
|
For strings:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::endsWith('ipsum')->validate('lorem ipsum'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
For arrays:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::endsWith('ipsum')->validate(array('lorem', 'ipsum')); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
A second parameter may be passed for identical comparison instead
|
|
|
|
of equal comparison.
|
|
|
|
|
|
|
|
Message template for this validator includes `{{endValue}}`.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::startsWith()](#vstartswithvalue)
|
|
|
|
* [v::contains()](#vcontainsvalue)
|
|
|
|
* [v::in()](#vin)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::equals($value)
|
|
|
|
#### v::equals($value, boolean $identical=false)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates if the input is equal some value.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::equals('alganet')->validate('alganet'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Identical validation (===) is possible:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::equals(10)->validate('10'); //true
|
|
|
|
v::equals(10, true)->validate('10'); //false
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Message template for this validator includes `{{compareTo}}`.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::contains()](#vcontainsvalue)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::even()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates an even number.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::int()->even()->validate(2); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Using `int()` before `even()` is a best practice.
|
|
|
|
|
|
|
|
See also
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::odd()](#vodd)
|
|
|
|
* [v::multiple()](#vmultiplemultipleof)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-11 09:13:15 +01:00
|
|
|
#### v::file()
|
|
|
|
|
|
|
|
Validates files.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::file()->validate(__FILE__); //true
|
|
|
|
v::file()->validate(__DIR__); //false
|
|
|
|
```
|
2013-01-11 09:13:15 +01:00
|
|
|
|
|
|
|
This validator will consider SplFileInfo instances, so you can do something like:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::file()->validate(new \SplFileInfo($file));
|
|
|
|
```
|
2013-01-11 09:13:15 +01:00
|
|
|
|
2013-01-11 09:34:26 +01:00
|
|
|
See also
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::directory()](#vdirectory)
|
|
|
|
* [v::exists()](#vexists)
|
2013-01-11 09:34:26 +01:00
|
|
|
|
2015-01-26 13:10:54 +01:00
|
|
|
#### v::filterVar(int $filter)
|
|
|
|
#### v::filterVar(int $filter, mixed $options)
|
|
|
|
|
|
|
|
A wrapper for PHP's [filter_var()](http://php.net/filter_var) function.
|
|
|
|
|
|
|
|
```php
|
|
|
|
v::filterVar(FILTER_VALIDATE_EMAIL)->validate('bob@example.com'); //true
|
|
|
|
v::filterVar(FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)->validate('http://example.com'); //true
|
|
|
|
```
|
|
|
|
|
|
|
|
See also
|
|
|
|
|
|
|
|
* [v::callback()](#vcallbackcallable-callback)
|
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::float()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates a floating point number.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::float()->validate(1.5); //true
|
|
|
|
v::float()->validate('1e5'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-23 00:10:33 +01:00
|
|
|
#### v::graph()
|
|
|
|
#### v::graph(string $additionalChars)
|
2013-01-21 16:44:49 +01:00
|
|
|
|
|
|
|
Validates all characters that are graphically represented.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::graph()->validate('LKM@#$%4;'); //true
|
|
|
|
```
|
2013-01-21 16:44:49 +01:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::prnt()](#vprnt)
|
2013-01-21 16:44:49 +01:00
|
|
|
|
|
|
|
#### v::hexa() *(deprecated)*
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-23 00:10:33 +01:00
|
|
|
Validates an hexadecimal number. It's now deprecated, xdigit should be used
|
2013-01-21 16:44:49 +01:00
|
|
|
instead.
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::hexa()->validate('AF12'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-21 16:44:49 +01:00
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::xdigit()](#vxdigit)
|
2013-01-21 16:44:49 +01:00
|
|
|
|
2014-07-16 10:02:26 +02:00
|
|
|
#### v::hexRgbColor()
|
|
|
|
|
|
|
|
Validates a hex RGB color
|
|
|
|
|
|
|
|
```php
|
|
|
|
v::hexRgbColor()->validate('#FFFAAA'); //true
|
|
|
|
v::hexRgbColor()->validate('123123'); //true
|
|
|
|
v::hexRgbColor()->validate('FCD'); //true
|
|
|
|
```
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
|
|
|
* [v::vxdigit()](#vxdigit)
|
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::in($haystack)
|
|
|
|
#### v::in($haystack, boolean $identical=false)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates if the input is contained in a specific haystack.
|
|
|
|
|
|
|
|
For strings:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::in('lorem ipsum')->validate('ipsum'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
For arrays:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::in(array('lorem', 'ipsum'))->validate('lorem'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
A second parameter may be passed for identical comparison instead
|
|
|
|
of equal comparison.
|
|
|
|
|
|
|
|
Message template for this validator includes `{{haystack}}`.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::startsWith()](#vstartswithvalue)
|
|
|
|
* [v::endsWith()](#vendswithvalue)
|
|
|
|
* [v::contains()](#vcontainsvalue)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::instance($instanceName)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates if the input is an instance of the given class or interface.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::instance('DateTime')->validate(new DateTime); //true
|
|
|
|
v::instance('Traversable')->validate(new ArrayObject); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Message template for this validator includes `{{instanceName}}`.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::object()](#vobject)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::int()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates if the input is an integer.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::int()->validate('10'); //true
|
|
|
|
v::int()->validate(10); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::numeric()](#vnumeric)
|
|
|
|
* [v::digit()](#vdigit)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::ip()
|
|
|
|
#### v::ip($options)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates IP Addresses. This validator uses the native filter_var()
|
|
|
|
PHP function.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::ip()->validate('192.168.0.1');
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
You can pass a parameter with filter_var flags for IP.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::ip(FILTER_FLAG_NO_PRIV_RANGE)->validate('127.0.0.1'); //false
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::json()
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-09 00:08:39 +02:00
|
|
|
Validates if the given input is a valid JSON.
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
2015-01-02 19:49:49 +01:00
|
|
|
v::json()->validate('{"foo":"bar"}'); //true
|
2014-04-12 16:59:10 +02:00
|
|
|
```
|
2011-02-07 15:46:08 +01:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::key($name)
|
|
|
|
#### v::key($name, v $validator)
|
|
|
|
#### v::key($name, v $validator, boolean $mandatory=true)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates an array key.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
$dict = array(
|
|
|
|
'foo' => 'bar'
|
|
|
|
);
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
v::key('foo')->validate($dict); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
You can also validate the key value itself:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::key('foo', v::equals('bar'))->validate($dict); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Third parameter makes the key presence optional:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::key('lorem', v::string(), false)->validate($dict); // true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
The name of this validator is automatically set to the key name.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::attribute()](#vattributename) - Validates a specific attribute of an object
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::leapDate($format)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates if a date is leap.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::leapDate('Y-m-d')->validate('1988-02-29'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
This validator accepts DateTime instances as well. The $format
|
|
|
|
parameter is mandatory.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::date()](#vdate)
|
|
|
|
* [v::leapYear()](#vleapyear)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::leapYear()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates if a year is leap.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::leapYear()->validate('1988'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
This validator accepts DateTime instances as well.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::date()](#vdate)
|
|
|
|
* [v::leapDate()](#vleapdateformat)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::length($min, $max)
|
|
|
|
#### v::length($min, null)
|
|
|
|
#### v::length(null, $max)
|
2014-12-29 01:31:06 +01:00
|
|
|
#### v::length($min, $max, boolean $inclusive=true)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates lengths. Most simple example:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::string()->length(1, 5)->validate('abc'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
You can also validate only minimum length:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::string()->length(5, null)->validate('abcdef'); // true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Only maximum length:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::string()->length(null, 5)->validate('abc'); // true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-22 22:08:38 +01:00
|
|
|
The type as the first validator in a chain is a good practice,
|
2012-04-09 00:08:39 +02:00
|
|
|
since length accepts many types:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::arr()->length(1, 5)->validate(array('foo', 'bar')); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
A third parameter may be passed to validate the passed values inclusive:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::string()->length(1, 5, true)->validate('a'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Message template for this validator includes `{{minValue}}` and `{{maxValue}}`.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::between()](#vbetweenstart-end) - Validates ranges
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::lowercase()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates if string characters are lowercase in the input:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::string()->lowercase()->validate('xkcd'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::uppercase()](#vuppercase)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::macAddress()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates a Mac Address.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::macAddress()->validate('00:11:22:33:44:55'); //true
|
2014-12-14 00:56:50 +01:00
|
|
|
v::macAddress()->validate('af-AA-22-33-44-55'); //true
|
2014-04-12 16:59:10 +02:00
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-12-04 20:35:36 +01:00
|
|
|
#### v::max($max)
|
|
|
|
#### v::max($max, boolean $inclusive=false)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates if the input doesn't exceed the maximum value.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::int()->max(15)->validate(20); //false
|
2014-12-04 20:38:23 +01:00
|
|
|
v::int()->max(20)->validate(20); //false
|
|
|
|
v::int()->max(20, true)->validate(20); //true
|
2014-04-12 16:59:10 +02:00
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Also accepts dates:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::date()->max('2012-01-01')->validate('2010-01-01'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-22 22:08:38 +01:00
|
|
|
`true` may be passed as a parameter to indicate that inclusive
|
2012-04-09 00:08:39 +02:00
|
|
|
values must be used.
|
|
|
|
|
|
|
|
Message template for this validator includes `{{maxValue}}`.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-12-04 20:38:23 +01:00
|
|
|
* [v::min()](#vminmin)
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::between()](#vbetweenstart-end)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-12-04 20:35:36 +01:00
|
|
|
#### v::min($min)
|
|
|
|
#### v::min($min, boolean $inclusive=false)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-12-04 20:35:36 +01:00
|
|
|
Validates if the input is greater than the minimum value.
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::int()->min(15)->validate(5); //false
|
2014-12-04 20:35:36 +01:00
|
|
|
v::int()->min(5)->validate(5); //false
|
|
|
|
v::int()->min(5, true)->validate(5); //true
|
2014-04-12 16:59:10 +02:00
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Also accepts dates:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::date()->min('2012-01-01')->validate('2015-01-01'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-22 22:08:38 +01:00
|
|
|
`true` may be passed as a parameter to indicate that inclusive
|
2012-04-09 00:08:39 +02:00
|
|
|
values must be used.
|
|
|
|
|
|
|
|
Message template for this validator includes `{{minValue}}`.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-12-04 20:38:23 +01:00
|
|
|
* [v::max()](#vmaxmax)
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::between()](#vbetweenstart-end)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::minimumAge($age)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates a minimum age for a given date.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::date()->minimumAge(18)->validate('1987-01-01'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Using `date()` before is a best-practice.
|
|
|
|
|
2013-01-22 22:08:38 +01:00
|
|
|
Message template for this validator includes `{{age}}`.
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::date()](#vdate)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::multiple($multipleOf)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates if the input is a multiple of the given parameter
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::int()->multiple(3)->validate(9); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::primeNumber()](#vprimenumber)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::negative()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates if a number is lower than zero
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::numeric()->negative()->validate(-15); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::positive()](#vpositive)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2015-01-06 23:14:08 +01:00
|
|
|
#### v::no($useLocale = false)
|
|
|
|
|
|
|
|
Validates if value is considered as "No".
|
|
|
|
|
|
|
|
```php
|
|
|
|
v::no()->validate('N'); //true
|
|
|
|
v::no()->validate('Nay'); //true
|
|
|
|
v::no()->validate('Nix'); //true
|
|
|
|
v::no()->validate('No'); //true
|
|
|
|
v::no()->validate('Nope'); //true
|
|
|
|
v::no()->validate('Not'); //true
|
|
|
|
```
|
|
|
|
|
|
|
|
This rule is case insensitive.
|
|
|
|
|
|
|
|
If `$useLocale` is TRUE, uses the value of [nl_langinfo()](http://php.net/nl_langinfo) with `NOEXPR` constant.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
|
|
|
* [v::yes()](#vyesuselocale--false)
|
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::noWhitespace()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates if a string contains no whitespace (spaces, tabs and line breaks);
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::noWhitespace()->validate('foo bar'); //false
|
|
|
|
v::noWhitespace()->validate("foo\nbar"); //false
|
|
|
|
```
|
2013-01-23 09:53:30 +01:00
|
|
|
|
|
|
|
Like other rules the input is still optional.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::string()->noWhitespace()->validate(''); //true
|
|
|
|
v::string()->noWhitespace()->validate(' '); //false
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
This is most useful when chaining with other validators such as `v::alnum()`
|
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::noneOf($v1, $v2, $v3...)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates if NONE of the given validators validate:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::noneOf(
|
|
|
|
v::int(),
|
|
|
|
v::float()
|
|
|
|
)->validate('foo'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
In the sample above, 'foo' isn't a integer nor a float, so noneOf returns true.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::not()](#vnotv-negatedvalidator)
|
|
|
|
* [v::allOf()](#vallofv1-v2-v3)
|
|
|
|
* [v::oneOf()](#voneofv1-v2-v3)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::not(v $negatedValidator)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Negates any rule.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::not(v::ip())->validate('foo'); //true
|
|
|
|
```
|
2013-01-22 22:08:38 +01:00
|
|
|
|
2013-02-26 00:15:23 +01:00
|
|
|
using a shortcut
|
2012-05-06 02:06:13 +02:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::ip()->not()->validate('foo'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
In the sample above, validator returns true because 'foo' isn't an IP Address.
|
|
|
|
|
|
|
|
You can negate complex, grouped or chained validators as well:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::not(v::int()->positive())->validate(-1.5); //true
|
|
|
|
```
|
2013-01-22 22:08:38 +01:00
|
|
|
|
2013-02-26 00:15:23 +01:00
|
|
|
using a shortcut
|
2012-05-06 02:06:13 +02:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::int()->positive()->not()->validate(-1.5); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Each other validation has custom messages for negated rules.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::noneOf()](#vnoneofv1-v2-v3)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::notEmpty()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-23 09:53:30 +01:00
|
|
|
Validates if the given input is not empty or in other words is input mandatory and
|
2013-02-26 00:15:23 +01:00
|
|
|
required. This function also takes whitespace into account, use `noWhitespace()`
|
2013-01-23 09:53:30 +01:00
|
|
|
if no spaces or linebreaks and other whitespace anywhere in the input is desired.
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::string()->notEmpty()->validate(''); //false
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Null values are empty:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::notEmpty()->validate(null); //false
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Numbers:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::int()->notEmpty()->validate(0); //false
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Empty arrays:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::arr()->notEmpty()->validate(array()); //false
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Whitespace:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::string()->notEmpty()->validate(' '); //false
|
|
|
|
v::string()->notEmpty()->validate("\t \n \r"); //false
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::noWhitespace()](#noWhitespace)
|
|
|
|
* [v::nullValue()](#vnullvalue)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::nullValue()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-23 09:53:30 +01:00
|
|
|
Validates if the input is null. This rule does not allow empty strings to avoid ambiguity.
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::nullValue()->validate(null); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::notEmpty()](#vnotempty)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::numeric()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates on any numeric value.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::numeric()->validate(-12); //true
|
|
|
|
v::numeric()->validate('135.0'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::int()](#vint)
|
|
|
|
* [v::digit()](#vdigit)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::object()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates if the input is an object.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::object()->validate(new stdClass); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::instance()](#vinstanceinstancename)
|
|
|
|
* [v::attribute()](#vattributename)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::odd()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates an odd number.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::int()->odd()->validate(3); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Using `int()` before `odd()` is a best practice.
|
|
|
|
|
|
|
|
See also
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::even()](#veven)
|
|
|
|
* [v::multiple()](#vmultiplemultipleof)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::oneOf($v1, $v2, $v3...)
|
2012-04-09 00:55:05 +02:00
|
|
|
|
|
|
|
This is a group validator that acts as an OR operator.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::oneOf(
|
|
|
|
v::int(),
|
|
|
|
v::float()
|
|
|
|
)->validate(15.5); //true
|
|
|
|
```
|
2012-04-09 00:55:05 +02:00
|
|
|
|
|
|
|
In the sample above, `v::int()` doesn't validates, but
|
|
|
|
`v::float()` validates, so oneOf returns true.
|
|
|
|
|
|
|
|
`v::oneOf` returns true if at least one inner validator
|
|
|
|
passes.
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-05-06 02:06:13 +02:00
|
|
|
Using a shortcut
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::int()->addOr(v::float())->validate(15.5); //true
|
|
|
|
```
|
2012-05-06 02:06:13 +02:00
|
|
|
|
2012-04-09 00:55:05 +02:00
|
|
|
See also:
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::allOf()](#vallofv1-v2-v3) - Similar to oneOf, but act as an AND operator
|
|
|
|
* [v::noneOf()](#vnoneofv1-v2-v3) - Validates if NONE of the inner rules validates
|
|
|
|
* [v::when()](#vwhenv-if-v-then-v-else) - A ternary validator
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::perfectSquare()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-09 00:55:05 +02:00
|
|
|
Validates a perfect square.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::perfectSquare()->validate(25); //true (5*5)
|
|
|
|
v::perfectSquare()->validate(9); //true (3*3)
|
|
|
|
```
|
2013-04-29 05:29:09 +02:00
|
|
|
#### v::phone()
|
|
|
|
|
2014-07-11 05:42:24 +02:00
|
|
|
Validates a valid 7, 10, 11 digit phone number (North America, Europe and most
|
|
|
|
Asian and Middle East countries), supporting country and area codes (in dot,
|
2013-04-29 05:29:09 +02:00
|
|
|
space or dashed notations) such as:
|
|
|
|
|
|
|
|
(555)555-5555
|
|
|
|
555 555 5555
|
|
|
|
+5(555)555.5555
|
|
|
|
33(1)22 22 22 22
|
|
|
|
+33(1)22 22 22 22
|
|
|
|
+33(020)7777 7777
|
|
|
|
03-6106666
|
2014-07-11 05:42:24 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::positive()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
Validates if a number is higher than zero
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::numeric()->positive()->validate(-15); //false
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::negative()](#vnegative)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2015-01-16 20:15:44 +01:00
|
|
|
#### v::postalCode(string $countryCode)
|
2015-01-02 21:39:58 +01:00
|
|
|
|
|
|
|
Validates a postal code according to the given country code.
|
|
|
|
|
|
|
|
```php
|
|
|
|
v::numeric()->postalCode('BR')->validate('02179000'); //true
|
|
|
|
v::numeric()->postalCode('BR')->validate('02179-000'); //true
|
|
|
|
v::numeric()->postalCode('US')->validate('02179-000'); //false
|
|
|
|
```
|
|
|
|
|
|
|
|
Extracted from [GeoNames](http://www.geonames.org/).
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
|
|
|
* [v::countryCode()](#vcountrycode)
|
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::primeNumber()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-09 00:55:05 +02:00
|
|
|
Validates a prime number
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::primeNumber()->validate(7); //true
|
|
|
|
```
|
2013-01-22 22:08:38 +01:00
|
|
|
|
2013-01-23 02:09:19 +01:00
|
|
|
#### v::prnt()
|
|
|
|
#### v::prnt(string $additionalChars)
|
2013-01-21 16:44:49 +01:00
|
|
|
|
2013-01-23 00:10:33 +01:00
|
|
|
Similar to `v::graph` but accepts whitespace.
|
2013-01-21 16:44:49 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::prnt()->validate('LMKA0$% _123'); //true
|
|
|
|
```
|
2013-01-21 16:44:49 +01:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::graph()](#vgraph)
|
2013-01-22 22:08:38 +01:00
|
|
|
|
2013-01-23 00:10:33 +01:00
|
|
|
#### v::punct()
|
|
|
|
#### v::punct(string $additionalChars)
|
2013-01-21 16:44:49 +01:00
|
|
|
|
|
|
|
Accepts only punctuation characters:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::punct()->validate('&,.;[]'); //true
|
|
|
|
```
|
2013-01-21 16:44:49 +01:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::cntrl()](#vcntrl)
|
|
|
|
* [v::graph()](#vgraph)
|
|
|
|
* [v::prnt()](#vprnt)
|
2012-04-09 00:55:05 +02:00
|
|
|
|
2013-02-05 01:20:49 +01:00
|
|
|
#### v::readable()
|
|
|
|
|
|
|
|
Validates if the given data is a file exists and is readable.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::readable()->validate('/path/of/a/readable/file'); //true
|
|
|
|
```
|
2013-02-05 01:20:49 +01:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::regex($regex)
|
2012-04-09 00:55:05 +02:00
|
|
|
|
|
|
|
Evaluates a regex on the input and validates if matches
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::regex('/[a-z]/')->validate('a'); //true
|
|
|
|
```
|
2012-04-09 00:55:05 +02:00
|
|
|
|
|
|
|
Message template for this validator includes `{{regex}}`
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::roman()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-09 00:55:05 +02:00
|
|
|
Validates roman numbers
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::roman()->validate('IV'); //true
|
|
|
|
```
|
2012-04-09 00:55:05 +02:00
|
|
|
|
|
|
|
This validator ignores empty values, use `notEmpty()` when
|
|
|
|
appropriate.
|
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::sf($sfValidator)
|
2012-04-09 00:55:05 +02:00
|
|
|
|
|
|
|
Use Symfony2 validators inside Respect\Validation flow. Messages
|
|
|
|
are preserved.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::sf('Time')->validate('15:00:00');
|
|
|
|
```
|
2012-04-09 00:55:05 +02:00
|
|
|
|
2015-01-17 18:24:18 +01:00
|
|
|
|
|
|
|
You must add `"symfony/validator": "~2.6"` to your `require` property on composer.json file.
|
|
|
|
|
2012-04-09 00:55:05 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::zend()](#vzendzendvalidator)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::slug()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-09 00:55:05 +02:00
|
|
|
Validates slug-like strings:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::slug()->validate('my-wordpress-title'); //true
|
|
|
|
v::slug()->validate('my-wordpress--title'); //false
|
|
|
|
v::slug()->validate('my-wordpress-title-'); //false
|
|
|
|
```
|
2012-04-09 00:55:05 +02:00
|
|
|
|
2013-01-21 16:44:49 +01:00
|
|
|
#### v::space()
|
|
|
|
#### v::space(string $additionalChars)
|
|
|
|
|
|
|
|
Accepts only whitespace:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::space()->validate(' '); //true
|
|
|
|
```
|
2013-01-21 16:44:49 +01:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::cntrl()](#vcntrl)
|
2013-01-21 16:44:49 +01:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::startsWith($value)
|
|
|
|
#### v::startsWith($value, boolean $identical=false)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
This validator is similar to `v::contains()`, but validates
|
2014-12-14 17:11:45 +01:00
|
|
|
only if the value is at the beginning of the input.
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
For strings:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::startsWith('lorem')->validate('lorem ipsum'); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
|
|
|
For arrays:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::startsWith('lorem')->validate(array('lorem', 'ipsum')); //true
|
|
|
|
```
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-02-26 00:15:23 +01:00
|
|
|
`true` may be passed as a parameter to indicate identical comparison
|
2012-04-09 00:08:39 +02:00
|
|
|
instead of equal.
|
|
|
|
|
|
|
|
Message template for this validator includes `{{startValue}}`.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::endsWith()](#vendswithvalue)
|
|
|
|
* [v::contains()](#vcontainsvalue)
|
|
|
|
* [v::in()](#vin)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::string()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-09 00:55:05 +02:00
|
|
|
Validates a string.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::string()->validate('hi'); //true
|
|
|
|
```
|
2012-04-09 00:55:05 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::alnum()](#valnum)
|
2012-04-09 00:55:05 +02:00
|
|
|
|
2013-02-05 00:55:19 +01:00
|
|
|
#### v::symbolicLink()
|
|
|
|
|
|
|
|
Validates if the given data is a path of a valid symbolic link.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::symbolicLink()->validate('/path/of/valid/symbolic/link'); //true
|
|
|
|
```
|
2013-02-05 00:55:19 +01:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::tld()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-09 00:55:05 +02:00
|
|
|
Validates a top-level domain
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::tld()->validate('com'); //true
|
|
|
|
v::tld()->validate('ly'); //true
|
|
|
|
v::tld()->validate('org'); //true
|
|
|
|
```
|
2012-04-09 00:55:05 +02:00
|
|
|
|
|
|
|
See also
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::domain()](#vdomain) - Validates domain names
|
|
|
|
* [v::countryCode()](#vcountrycode) - Validates ISO country codes
|
2012-04-09 00:55:05 +02:00
|
|
|
|
2015-01-22 17:43:58 +01:00
|
|
|
#### v::true()
|
|
|
|
|
|
|
|
Validates if a value is considered as `true`.
|
|
|
|
|
|
|
|
```php
|
|
|
|
v::true()->validate(true); //true
|
|
|
|
v::true()->validate(1); //true
|
|
|
|
v::true()->validate('1'); //true
|
|
|
|
v::true()->validate('true'); //true
|
|
|
|
v::true()->validate('on'); //true
|
|
|
|
v::true()->validate('yes'); //true
|
|
|
|
```
|
|
|
|
|
2015-01-22 17:47:55 +01:00
|
|
|
See also
|
|
|
|
|
|
|
|
* [v::false()](#vfalse)
|
|
|
|
|
2013-02-05 01:41:35 +01:00
|
|
|
#### v::uploaded()
|
|
|
|
|
2013-10-01 02:29:30 +02:00
|
|
|
Validates if the given data is a file that was uploaded via HTTP POST.
|
2013-02-05 01:41:35 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::uploaded()->validate('/path/of/an/uploaded/file'); //true
|
|
|
|
```
|
2013-02-05 01:41:35 +01:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::uppercase()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-09 00:55:05 +02:00
|
|
|
Validates if string characters are uppercase in the input:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::string()->uppercase()->validate('W3C'); //true
|
|
|
|
```
|
2012-04-09 00:55:05 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::lowercase()](#vlowercase)
|
2012-04-09 00:55:05 +02:00
|
|
|
|
2015-01-27 13:25:20 +01:00
|
|
|
#### v::url()
|
|
|
|
|
|
|
|
Validates if input is an URL:
|
|
|
|
|
|
|
|
```php
|
|
|
|
v::url()->validate('http://example.com'); //true
|
|
|
|
v::url()->validate('https://www.youtube.com/watch?v=6FOUqQt3Kg0'); //true
|
|
|
|
v::url()->validate('ldap://[::1]'); //true
|
|
|
|
v::url()->validate('mailto:john.doe@example.com'); //true
|
|
|
|
v::url()->validate('news:new.example.com'); //true
|
|
|
|
```
|
|
|
|
|
|
|
|
This rule uses [v::filterVar()](#vfiltervarint-filter) rule with `FILTER_VALIDATE_URL` flag.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
|
|
|
* [v::domain()](#vdomain)
|
|
|
|
* [v::filterVar()](#vfiltervarint-filter)
|
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::version()
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2012-04-09 00:55:05 +02:00
|
|
|
Validates version numbers using Semantic Versioning.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::version()->validate('1.0.0');
|
|
|
|
```
|
2012-04-09 00:55:05 +02:00
|
|
|
|
2013-01-22 22:53:27 +01:00
|
|
|
#### v::vowels() *(deprecated)*
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-22 22:53:27 +01:00
|
|
|
Validates strings that contains only vowels. It's now deprecated, vowel should be used
|
|
|
|
instead.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::vowel()](#vvowel)
|
2013-01-22 22:53:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
#### v::vowel()
|
|
|
|
|
|
|
|
Similar to `v::alnum()`. Validates strings that contains only vowels:
|
2012-04-09 00:55:05 +02:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::vowel()->validate('aei'); //true
|
|
|
|
```
|
2012-04-09 00:55:05 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::alnum()](#valnum) - a-z0-9, empty or whitespace only
|
|
|
|
* [v::digit()](#vdigit) - 0-9, empty or whitespace only
|
|
|
|
* [v::alpha()](#valpha) - a-Z, empty or whitespace only
|
|
|
|
* [v::consonant()](#vconsonant)
|
2012-04-09 00:55:05 +02:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::when(v $if, v $then, v $else)
|
2015-01-17 00:42:57 +01:00
|
|
|
#### v::when(v $if, v $then)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-01-22 22:08:38 +01:00
|
|
|
A ternary validator that accepts three parameters.
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2015-01-17 00:42:57 +01:00
|
|
|
When the `$if` validates, returns validation for `$then`.
|
|
|
|
When the `$if` doesn't validate, returns validation for `$else`, if defined.
|
2012-04-09 00:55:05 +02:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::when(v::int(), v::positive(), v::notEmpty())->validate($input);
|
|
|
|
```
|
2012-04-09 00:55:05 +02:00
|
|
|
|
|
|
|
In the sample above, if `$input` is an integer, then it must be positive.
|
|
|
|
If `$input` is not an integer, then it must not me empty.
|
2015-01-17 00:42:57 +01:00
|
|
|
When `$else` is not defined use [v::alwaysInvalid()](#valwaysinvalid) as default.
|
2012-04-09 00:55:05 +02:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::allOf()](#vallofv1-v2-v3)
|
|
|
|
* [v::oneOf()](#voneofv1-v2-v3)
|
|
|
|
* [v::noneOf()](#vnoneofv1-v2-v3)
|
2012-04-09 00:55:05 +02:00
|
|
|
|
2013-01-23 00:10:33 +01:00
|
|
|
#### v::xdigit()
|
2013-01-21 16:44:49 +01:00
|
|
|
|
|
|
|
Accepts an hexadecimal number:
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::xdigit()->validate('abc123'); //true
|
|
|
|
```
|
2013-01-21 16:44:49 +01:00
|
|
|
|
2013-01-23 00:10:33 +01:00
|
|
|
Notice, however, that it doesn't accept strings starting with 0x:
|
2013-01-21 16:44:49 +01:00
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::xdigit()->validate('0x1f'); //false
|
|
|
|
```
|
2013-01-21 16:44:49 +01:00
|
|
|
|
|
|
|
See also:
|
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::digit()](#vdigit)
|
|
|
|
* [v::alnum()](#valnum)
|
2014-07-16 10:02:26 +02:00
|
|
|
* [v::hexRgbColor()](#vhexrgbcolor)
|
2013-01-21 16:44:49 +01:00
|
|
|
|
2015-01-06 23:14:08 +01:00
|
|
|
#### v::yes($useLocale = false)
|
|
|
|
|
|
|
|
Validates if value is considered as "Yes".
|
|
|
|
|
|
|
|
```php
|
|
|
|
v::yes()->validate('Y');//true
|
|
|
|
v::yes()->validate('Yea');//true
|
|
|
|
v::yes()->validate('Yeah');//true
|
|
|
|
v::yes()->validate('Yep');//true
|
|
|
|
v::yes()->validate('Yes');//true
|
|
|
|
```
|
|
|
|
|
|
|
|
This rule is case insensitive.
|
|
|
|
|
|
|
|
If `$useLocale` is TRUE, uses the value of [nl_langinfo()](http://php.net/nl_langinfo) with `YESEXPR` constant.
|
|
|
|
|
|
|
|
See also:
|
|
|
|
|
|
|
|
* [v::no()](#vnouselocale--false)
|
|
|
|
|
2013-02-05 01:26:38 +01:00
|
|
|
#### v::writable()
|
|
|
|
|
|
|
|
Validates if the given data is a file exists and is writable.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::writable()->validate('/path/of/a/writable/file'); //true
|
|
|
|
```
|
2013-02-05 01:26:38 +01:00
|
|
|
|
2012-04-10 03:46:28 +02:00
|
|
|
#### v::zend($zendValidator)
|
2012-04-09 00:55:05 +02:00
|
|
|
|
|
|
|
Use Zend validators inside Respect\Validation flow. Messages
|
|
|
|
are preserved.
|
|
|
|
|
2014-04-12 16:59:10 +02:00
|
|
|
```php
|
|
|
|
v::zend('Hostname')->validate('google.com');
|
|
|
|
```
|
2012-04-09 00:55:05 +02:00
|
|
|
|
2015-01-17 18:24:18 +01:00
|
|
|
You must add `"zendframework/zend-validator": "~2.3"` to your `require` property on composer.json file.
|
2012-04-09 00:55:05 +02:00
|
|
|
|
|
|
|
See also:
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2014-06-27 14:50:19 +02:00
|
|
|
* [v::sf()](#vsfsfvalidator)
|
2012-04-09 00:08:39 +02:00
|
|
|
|
2013-09-01 17:16:05 +02:00
|
|
|
[PunnyCode]: http://en.wikipedia.org/wiki/Punycode "Wikipedia: Punnycode"
|
|
|
|
[IDNA]: http://en.wikipedia.org/wiki/Internationalized_domain_name#Internationalizing_Domain_Names_in_Applications "Wikipedia: Internationalized domain name"
|