mirror of
https://github.com/Respect/Validation.git
synced 2024-06-04 14:52:17 +02:00
Update documentation
This commit is contained in:
parent
16a72ade95
commit
f422020d0e
|
@ -11,7 +11,7 @@ Due to time constraints, we are not always able to respond as quickly as we
|
|||
would like. Please do not take delays personal and feel free to remind us here,
|
||||
on IRC, or on Gitter if you feel that we forgot to respond.
|
||||
|
||||
Please see the [project documentation](http://documentup.com/Respect/Validation)
|
||||
Please see the [project documentation](http://respect.github.io/Validation)
|
||||
before proceeding. You should also know about [PHP-FIG](http://www.php-fig.org)'s
|
||||
standards and basic unit testing, but we're sure you can learn that just by
|
||||
looking at other rules. Pick the simple ones like `Int` to begin.
|
||||
|
@ -113,9 +113,9 @@ PS.: We strongly recommend you use [Data Providers](https://phpunit.de/manual/cu
|
|||
|
||||
## Documentation
|
||||
|
||||
Our docs at http://documentup.com/Respect/Validation are generated from our
|
||||
Markdown files. Add your brand new rule there and everything will be updated as
|
||||
soon as possible.
|
||||
Our docs at http://respect.github.io/Validation are generated from our Markdown
|
||||
files using [Couscous](http://couscous.io/). Add your brand new rule there and
|
||||
everything will be updated as soon as possible.
|
||||
|
||||
## Running Tests
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
Copyright (c) 2009-2015, Alexandre Gomes Gaigalas.
|
||||
# License
|
||||
|
||||
Copyright (c) 2009-2015, [Alexandre Gomes Gaigalas](http://github.com/alganet).
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
29
docs/AllOf.md
Normal file
29
docs/AllOf.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
# AllOf
|
||||
|
||||
- `v::allOf(v $v1, v $v2, v $v3...)`
|
||||
|
||||
Will validate if all inner validators validates.
|
||||
|
||||
```php
|
||||
v::allOf(
|
||||
v::int(),
|
||||
v::positive()
|
||||
)->validate(15); //true
|
||||
```
|
||||
|
||||
This is similar to the chain (which is an allOf already), but
|
||||
its syntax allows you to set custom names for every node:
|
||||
|
||||
```php
|
||||
v::allOf(
|
||||
v::int()->setName('Account Number'),
|
||||
v::positive()->setName('Higher Than Zero')
|
||||
)->setName('Positive integer')
|
||||
->validate(15); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [OneOf](OneOf.md)
|
||||
* [NoneOf](NoneOf.md)
|
||||
* [When](When.md)
|
47
docs/Alnum.md
Normal file
47
docs/Alnum.md
Normal file
|
@ -0,0 +1,47 @@
|
|||
# Alnum
|
||||
|
||||
- `v::alnum()`
|
||||
- `v::alnum(string $additionalChars)`
|
||||
|
||||
Validates alphanumeric characters from a-Z and 0-9.
|
||||
|
||||
```php
|
||||
v::alnum()->validate('foo 123'); //true
|
||||
```
|
||||
|
||||
A parameter for extra characters can be used:
|
||||
|
||||
```php
|
||||
v::alnum('-')->validate('foo - 123'); //true
|
||||
```
|
||||
|
||||
This validator allows whitespace, if you want to
|
||||
remove them add `->noWhitespace()` to the chain:
|
||||
|
||||
```php
|
||||
v::alnum()->noWhitespace->validate('foo 123'); //false
|
||||
```
|
||||
|
||||
By default empty values are allowed, if you want
|
||||
to invalidate them, add `->notEmpty()` to the chain:
|
||||
|
||||
```php
|
||||
v::alnum()->notEmpty()->validate(''); //false
|
||||
```
|
||||
|
||||
You can restrict case using the `->lowercase()` and
|
||||
`->uppercase()` validators:
|
||||
|
||||
```php
|
||||
v::alnum()->uppercase()->validate('aaa'); //false
|
||||
```
|
||||
|
||||
Message template for this validator includes `{{additionalChars}}` as
|
||||
the string of extra chars passed as the parameter.
|
||||
|
||||
See also:
|
||||
|
||||
* [Alpha](Alpha.md)
|
||||
* [Digit](Digit.md)
|
||||
* [Consonant](Consonant.md)
|
||||
* [Vowel](Vowel.md)
|
15
docs/Alpha.md
Normal file
15
docs/Alpha.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Alpha
|
||||
|
||||
- `v::alpha()`
|
||||
- `v::alpha(string $additionalChars)`
|
||||
|
||||
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.
|
||||
|
||||
See also:
|
||||
|
||||
* [Alnum](Alnum.md)
|
||||
* [Digit](Digit.md)
|
||||
* [Consonant](Consonant.md)
|
||||
* [Vowel](Vowel.md)
|
13
docs/AlwaysInvalid.md
Normal file
13
docs/AlwaysInvalid.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# AlwaysInvalid
|
||||
|
||||
- `v::alwaysInvalid()`
|
||||
|
||||
Always return false.
|
||||
|
||||
```php
|
||||
v::alwaysInvalid()->validate($whatever); //false
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [AlwaysValid](AlwaysValid.md)
|
13
docs/AlwaysValid.md
Normal file
13
docs/AlwaysValid.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# AlwaysValid
|
||||
|
||||
- `v::alwaysValid()`
|
||||
|
||||
Always returns true.
|
||||
|
||||
```php
|
||||
v::alwaysValid()->validate($whatever); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [AlwaysInvalid](AlwaysInvalid.md)
|
15
docs/Arr.md
Normal file
15
docs/Arr.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Arr
|
||||
|
||||
- `v::arr()`
|
||||
|
||||
Validates if the input is an array or traversable object.
|
||||
|
||||
```php
|
||||
v::arr()->validate(array()); //true
|
||||
v::arr()->validate(new ArrayObject); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Each](Each.md)
|
||||
* [Key](Key.md)
|
32
docs/Attribute.md
Normal file
32
docs/Attribute.md
Normal file
|
@ -0,0 +1,32 @@
|
|||
# Attribute
|
||||
|
||||
- `v::attribute(string $name)`
|
||||
- `v::attribute(string $name, v $validator)`
|
||||
- `v::attribute(string $name, v $validator, boolean $mandatory = true)`
|
||||
|
||||
Validates an object attribute.
|
||||
|
||||
```php
|
||||
$obj = new stdClass;
|
||||
$obj->foo = 'bar';
|
||||
|
||||
v::attribute('foo')->validate($obj); //true
|
||||
```
|
||||
|
||||
You can also validate the attribute itself:
|
||||
|
||||
```php
|
||||
v::attribute('foo', v::equals('bar'))->validate($obj); //true
|
||||
```
|
||||
|
||||
Third parameter makes the attribute presence optional:
|
||||
|
||||
```php
|
||||
v::attribute('lorem', v::string(), false)->validate($obj); // true
|
||||
```
|
||||
|
||||
The name of this validator is automatically set to the attribute name.
|
||||
|
||||
See also:
|
||||
|
||||
* [Key](Key.md)
|
19
docs/Bank.md
Normal file
19
docs/Bank.md
Normal file
|
@ -0,0 +1,19 @@
|
|||
# Bank
|
||||
|
||||
- `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:
|
||||
|
||||
* "de" (Germany) - You must add `"malkusch/bav": "~1.0"` to your `require` property on composer.json file.
|
||||
|
||||
See also
|
||||
|
||||
* [BankAccount](BankAccount.md)
|
||||
* [Bic](Bic.md)
|
19
docs/BankAccount.md
Normal file
19
docs/BankAccount.md
Normal file
|
@ -0,0 +1,19 @@
|
|||
# BankAccount
|
||||
|
||||
- `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:
|
||||
|
||||
* "de" (Germany) - You must add `"malkusch/bav": "~1.0"` to your `require` property on composer.json file.
|
||||
|
||||
See also
|
||||
|
||||
* [Bank](Bank.md)
|
||||
* [Bic](Bic.md)
|
43
docs/Between.md
Normal file
43
docs/Between.md
Normal file
|
@ -0,0 +1,43 @@
|
|||
# Between
|
||||
|
||||
- `v::between(mixed $start, mixed $end)`
|
||||
- `v::between(mixed $start, mixed $end, boolean $inclusive = false)`
|
||||
|
||||
Validates ranges. Most simple example:
|
||||
|
||||
```php
|
||||
v::int()->between(10, 20)->validate(15); //true
|
||||
```
|
||||
|
||||
The type as the first validator in a chain is a good practice,
|
||||
since between accepts many types:
|
||||
|
||||
```php
|
||||
v::string()->between('a', 'f')->validate('c'); //true
|
||||
```
|
||||
|
||||
Also very powerful with dates:
|
||||
|
||||
```php
|
||||
v::date()->between('2009-01-01', '2013-01-01')->validate('2010-01-01'); //true
|
||||
```
|
||||
|
||||
Date ranges accept strtotime values:
|
||||
|
||||
```php
|
||||
v::date()->between('yesterday', 'tomorrow')->validate('now'); //true
|
||||
```
|
||||
|
||||
A third parameter may be passed to validate the passed values inclusive:
|
||||
|
||||
```php
|
||||
v::date()->between(10, 20, true)->validate(20); //true
|
||||
```
|
||||
|
||||
Message template for this validator includes `{{minValue}}` and `{{maxValue}}`.
|
||||
|
||||
See also:
|
||||
|
||||
* [Length](Length.md)
|
||||
* [Min](Min.md)
|
||||
* [Max](Max.md)
|
19
docs/Bic.md
Normal file
19
docs/Bic.md
Normal file
|
@ -0,0 +1,19 @@
|
|||
# Bic
|
||||
|
||||
- `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:
|
||||
|
||||
* "de" (Germany) - You must add `"malkusch/bav": "~1.0"` to your `require` property on composer.json file.
|
||||
|
||||
See also
|
||||
|
||||
* [Bank](Bank.md)
|
||||
* [BankAccount](BankAccount.md)
|
10
docs/Bool.md
Normal file
10
docs/Bool.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
# Bool
|
||||
|
||||
- `v::bool()`
|
||||
|
||||
Validates if the input is a boolean value:
|
||||
|
||||
```php
|
||||
v::bool()->validate(true); //true
|
||||
v::bool()->validate(false); //true
|
||||
```
|
50
docs/Call.md
Normal file
50
docs/Call.md
Normal file
|
@ -0,0 +1,50 @@
|
|||
# Call
|
||||
|
||||
- `v::call(callable $callback)`
|
||||
|
||||
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:
|
||||
|
||||
```php
|
||||
$url = 'http://www.google.com/search?q=respect.github.com'
|
||||
```
|
||||
|
||||
To validate every part of this URL we could use the native `parse_url`
|
||||
function to break its parts:
|
||||
|
||||
```php
|
||||
$parts = parse_url($url);
|
||||
```
|
||||
|
||||
This function returns an array containing `scheme`, `host`, `path` and `query`.
|
||||
We can validate them this way:
|
||||
|
||||
```php
|
||||
v::arr()->key('scheme', v::startsWith('http'))
|
||||
->key('host', v::domain())
|
||||
->key('path', v::string())
|
||||
->key('query', v::notEmpty());
|
||||
```
|
||||
|
||||
Using `v::call()` you can do this in a single chain:
|
||||
|
||||
```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);
|
||||
```
|
||||
|
||||
It is possible to call methods and closures as the first parameter:
|
||||
|
||||
```php
|
||||
v::call(array($myObj, 'methodName'), v::int())->validate($myInput);
|
||||
v::call(function($input) {}, v::int())->validate($myInput);
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Callback](Callback.md)
|
19
docs/Callback.md
Normal file
19
docs/Callback.md
Normal file
|
@ -0,0 +1,19 @@
|
|||
# Callback
|
||||
|
||||
- `v::callback(callable $callback)`
|
||||
|
||||
This is a wildcard validator, it uses a function name, method or closure
|
||||
to validate something:
|
||||
|
||||
```php
|
||||
v::callback('is_int')->validate(10); //true
|
||||
```
|
||||
|
||||
(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:
|
||||
|
||||
* [Call](Call.md)
|
||||
* [FilterVar](FilterVar.md)
|
13
docs/Charset.md
Normal file
13
docs/Charset.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Charset
|
||||
|
||||
- `v::charset(mixed $charset)`
|
||||
|
||||
Validates if a string is in a specific charset.
|
||||
|
||||
```php
|
||||
v::charset('ASCII')->validate('açúcar'); //false
|
||||
v::charset('ASCII')->validate('sugar'); //true
|
||||
v::charset(array('ISO-8859-1', 'EUC-JP'))->validate('日本国'); // true
|
||||
```
|
||||
|
||||
The array format is a logic OR, not AND.
|
14
docs/Cnh.md
Normal file
14
docs/Cnh.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Cnh
|
||||
|
||||
- `v::cnh()`
|
||||
|
||||
Validates a Brazillian driver's license.
|
||||
|
||||
```php
|
||||
v::cnh()->validate('02650306461'); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Cnpj](Cnpj.md)
|
||||
* [Cpf](Cpf.md)
|
11
docs/Cnpj.md
Normal file
11
docs/Cnpj.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Cnpj
|
||||
|
||||
- `v::cnpj()`
|
||||
|
||||
Validates the Brazillian CNPJ number. Ignores non-digit chars, so
|
||||
use `->digit()` if needed.
|
||||
|
||||
See also:
|
||||
|
||||
* [Cpf](Cpf.md)
|
||||
* [Cnh](Cnh.md)
|
16
docs/Cntrl.md
Normal file
16
docs/Cntrl.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Cntrl
|
||||
|
||||
- `v::cntrl()`
|
||||
- `v::cntrl(string $additionalChars)`
|
||||
|
||||
This is similar to `v::alnum()`, but only accepts control characters:
|
||||
|
||||
```php
|
||||
v::cntrl()->validate("\n\r\t"); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Alnum](Alnum.md)
|
||||
* [Prnt](Prnt.md)
|
||||
* [Space](Space.md)
|
17
docs/Consonant.md
Normal file
17
docs/Consonant.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Consonant
|
||||
|
||||
- `v::consonant()`
|
||||
- `v::consonant(string $additionalChars)`
|
||||
|
||||
Similar to `v::alnum()`. Validates strings that contain only consonants:
|
||||
|
||||
```php
|
||||
v::consonant()->validate('xkcd'); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Alnum](Alnum.md)
|
||||
* [Digit](Digit.md)
|
||||
* [Alpha](Alpha.md)
|
||||
* [Vowel](Vowel.md)
|
27
docs/Contains.md
Normal file
27
docs/Contains.md
Normal file
|
@ -0,0 +1,27 @@
|
|||
# Contains
|
||||
|
||||
- `v::contains(mixed $value)`
|
||||
- `v::contains(mixed $value, boolean $identical = false)`
|
||||
|
||||
For strings:
|
||||
|
||||
```php
|
||||
v::contains('ipsum')->validate('lorem ipsum'); //true
|
||||
```
|
||||
|
||||
For arrays:
|
||||
|
||||
```php
|
||||
v::contains('ipsum')->validate(array('ipsum', 'lorem')); //true
|
||||
```
|
||||
|
||||
A second parameter may be passed for identical comparison instead
|
||||
of equal comparison.
|
||||
|
||||
Message template for this validator includes `{{containsValue}}`.
|
||||
|
||||
See also:
|
||||
|
||||
* [StartsWith](StartsWith.md)
|
||||
* [EndsWith](EndsWith.md)
|
||||
* [In](In.md)
|
13
docs/CountryCode.md
Normal file
13
docs/CountryCode.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# CountryCode
|
||||
|
||||
- `v::countryCode()`
|
||||
|
||||
Validates an ISO country code like US or BR.
|
||||
|
||||
```php
|
||||
v::countryCode()->validate('BR'); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Tld](Tld.md)
|
27
docs/Cpf.md
Normal file
27
docs/Cpf.md
Normal file
|
@ -0,0 +1,27 @@
|
|||
# Cpf
|
||||
|
||||
- `v::cpf()`
|
||||
|
||||
Validates a Brazillian CPF number.
|
||||
|
||||
```php
|
||||
v::cpf()->validate('44455566820'); //true
|
||||
```
|
||||
|
||||
It ignores any non-digit char:
|
||||
|
||||
```php
|
||||
v::cpf()->validate('444.555.668-20'); //true
|
||||
```
|
||||
|
||||
If you need to validate digits only, add `->digit()` to
|
||||
the chain:
|
||||
|
||||
```php
|
||||
v::digit()->cpf()->validate('44455566820'); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Cnpj](Cnpj.md)
|
||||
* [Cnh](Cnh.md)
|
15
docs/CreditCard.md
Normal file
15
docs/CreditCard.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# CreditCard
|
||||
|
||||
- `v::creditCard()`
|
||||
|
||||
Validates a credit card number.
|
||||
|
||||
```php
|
||||
v::creditCard()->validate('5376 7473 9720 8720'); //true
|
||||
```
|
||||
|
||||
It ignores any non-digit chars, so use `->digit()` when appropriate.
|
||||
|
||||
```php
|
||||
v::digit()->creditCard()->validate('5376747397208720'); //true
|
||||
```
|
39
docs/Date.md
Normal file
39
docs/Date.md
Normal file
|
@ -0,0 +1,39 @@
|
|||
# Date
|
||||
|
||||
- `v::date()`
|
||||
- `v::date(string $format)`
|
||||
|
||||
Validates if input is a date:
|
||||
|
||||
```php
|
||||
v::date()->validate('2009-01-01'); //true
|
||||
```
|
||||
|
||||
Also accepts strtotime values:
|
||||
|
||||
```php
|
||||
v::date()->validate('now'); //true
|
||||
```
|
||||
|
||||
And DateTime instances:
|
||||
|
||||
```php
|
||||
v::date()->validate(new DateTime); //true
|
||||
```
|
||||
|
||||
You can pass a format when validating strings:
|
||||
|
||||
```php
|
||||
v::date('Y-m-d')->validate('01-01-2009'); //false
|
||||
```
|
||||
|
||||
Format has no effect when validating DateTime instances.
|
||||
|
||||
Message template for this validator includes `{{format}}`.
|
||||
|
||||
See also:
|
||||
|
||||
* [Between](Between.md)
|
||||
* [MinimumAge](MinimumAge.md)
|
||||
* [LeapDate](LeapDate.md)
|
||||
* [LeapYear](LeapYear.md)
|
14
docs/Digit.md
Normal file
14
docs/Digit.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Digit
|
||||
|
||||
- `v::digit()`
|
||||
|
||||
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.
|
||||
|
||||
See also:
|
||||
|
||||
* [Alnum](Alnum.md)
|
||||
* [Alpha](Alpha.md)
|
||||
* [Vowel](Vowel.md)
|
||||
* [Consonant](Consonant.md)
|
21
docs/Directory.md
Normal file
21
docs/Directory.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Directory
|
||||
|
||||
- `v::directory()`
|
||||
|
||||
Validates directories.
|
||||
|
||||
```php
|
||||
v::directory()->validate(__DIR__); //true
|
||||
v::directory()->validate(__FILE__); //false
|
||||
```
|
||||
|
||||
This validator will consider SplFileInfo instances, so you can do something like:
|
||||
|
||||
```php
|
||||
v::directory()->validate(new \SplFileInfo($directory));
|
||||
```
|
||||
|
||||
See also
|
||||
|
||||
* [Exists](Exists.md)
|
||||
* [File](File.md)
|
38
docs/Domain.md
Normal file
38
docs/Domain.md
Normal file
|
@ -0,0 +1,38 @@
|
|||
# Domain
|
||||
|
||||
- `v::domain()`
|
||||
- `v::domain(boolean $tldCheck = true)`
|
||||
|
||||
Validates domain names.
|
||||
|
||||
```php
|
||||
v::domain()->validate('google.com');
|
||||
```
|
||||
|
||||
You can skip *top level domain* (TLD) checks to validate internal
|
||||
domain names:
|
||||
|
||||
```php
|
||||
v::domain(false)->validate('dev.machine.local');
|
||||
```
|
||||
|
||||
This is a composite validator, it validates several rules
|
||||
internally:
|
||||
|
||||
* If input is an IP address, it fails.
|
||||
* If input contains whitespace, it fails.
|
||||
* If input does not contain any dots, it fails.
|
||||
* 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].
|
||||
|
||||
Messages for this validator will reflect rules above.
|
||||
|
||||
See also:
|
||||
|
||||
* [Tld](Tld.md)
|
||||
* [Ip](Ip.md)
|
||||
|
||||
[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"
|
26
docs/Each.md
Normal file
26
docs/Each.md
Normal file
|
@ -0,0 +1,26 @@
|
|||
# Each
|
||||
|
||||
- `v::each(v $validatorForValue)`
|
||||
- `v::each(null, v $validatorForKey)`
|
||||
- `v::each(v $validatorForValue, v $validatorForKey)`
|
||||
|
||||
Iterates over an array or Iterator and validates the value or key
|
||||
of each entry:
|
||||
|
||||
```php
|
||||
$releaseDates = array(
|
||||
'validation' => '2010-01-01',
|
||||
'template' => '2011-01-01',
|
||||
'relational' => '2011-02-05',
|
||||
);
|
||||
|
||||
v::arr()->each(v::date())->validate($releaseDates); //true
|
||||
v::arr()->each(v::date(), v::string()->lowercase())->validate($releaseDates); //true
|
||||
```
|
||||
|
||||
Using `arr()` before `each()` is a best practice.
|
||||
|
||||
See also:
|
||||
|
||||
* [Key](Key.md)
|
||||
* [Arr](Arr.md)
|
9
docs/Email.md
Normal file
9
docs/Email.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Email
|
||||
|
||||
- `v::email()`
|
||||
|
||||
Validates an email address.
|
||||
|
||||
```php
|
||||
v::email()->validate('alexandre@gaigalas.net'); //true
|
||||
```
|
30
docs/EndsWith.md
Normal file
30
docs/EndsWith.md
Normal file
|
@ -0,0 +1,30 @@
|
|||
# EndsWith
|
||||
|
||||
- `v::endsWith(mixed $value)`
|
||||
- `v::endsWith(mixed $value, boolean $identical = false)`
|
||||
|
||||
This validator is similar to `v::contains()`, but validates
|
||||
only if the value is at the end of the input.
|
||||
|
||||
For strings:
|
||||
|
||||
```php
|
||||
v::endsWith('ipsum')->validate('lorem ipsum'); //true
|
||||
```
|
||||
|
||||
For arrays:
|
||||
|
||||
```php
|
||||
v::endsWith('ipsum')->validate(array('lorem', 'ipsum')); //true
|
||||
```
|
||||
|
||||
A second parameter may be passed for identical comparison instead
|
||||
of equal comparison.
|
||||
|
||||
Message template for this validator includes `{{endValue}}`.
|
||||
|
||||
See also:
|
||||
|
||||
* [StartsWith](StartsWith.md)
|
||||
* [Contains](Contains.md)
|
||||
* [In](In.md)
|
23
docs/Equals.md
Normal file
23
docs/Equals.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Equals
|
||||
|
||||
- `v::equals(mixed $value)`
|
||||
- `v::equals(mixed $value, boolean $identical = false)`
|
||||
|
||||
Validates if the input is equal some value.
|
||||
|
||||
```php
|
||||
v::equals('alganet')->validate('alganet'); //true
|
||||
```
|
||||
|
||||
Identical validation (===) is possible:
|
||||
|
||||
```php
|
||||
v::equals(10)->validate('10'); //true
|
||||
v::equals(10, true)->validate('10'); //false
|
||||
```
|
||||
|
||||
Message template for this validator includes `{{compareTo}}`.
|
||||
|
||||
See also:
|
||||
|
||||
* [Contains](Contains.md)
|
16
docs/Even.md
Normal file
16
docs/Even.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Even
|
||||
|
||||
- `v::even()`
|
||||
|
||||
Validates an even number.
|
||||
|
||||
```php
|
||||
v::int()->even()->validate(2); //true
|
||||
```
|
||||
|
||||
Using `int()` before `even()` is a best practice.
|
||||
|
||||
See also
|
||||
|
||||
* [Odd](Odd.md)
|
||||
* [Multiple](Multiple.md)
|
14
docs/Executable.md
Normal file
14
docs/Executable.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Executable
|
||||
|
||||
- `v::executable()`
|
||||
|
||||
Validates if a file is an executable.
|
||||
|
||||
```php
|
||||
v::email()->executable('script.sh'); //true
|
||||
```
|
||||
|
||||
See also
|
||||
|
||||
* [Readable](Readable.md)
|
||||
* [Writable](Writable.md)
|
21
docs/Exists.md
Normal file
21
docs/Exists.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Exists
|
||||
|
||||
- `v::exists()`
|
||||
|
||||
Validates files or directories.
|
||||
|
||||
```php
|
||||
v::exists()->validate(__FILE__); //true
|
||||
v::exists()->validate(__DIR__); //true
|
||||
```
|
||||
|
||||
This validator will consider SplFileInfo instances, so you can do something like:
|
||||
|
||||
```php
|
||||
v::exists()->validate(new \SplFileInfo($file));
|
||||
```
|
||||
|
||||
See also
|
||||
|
||||
* [Directory](Directory.md)
|
||||
* [File](File.md)
|
18
docs/False.md
Normal file
18
docs/False.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
# False
|
||||
|
||||
- `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
|
||||
|
||||
* [True](True.md)
|
21
docs/File.md
Normal file
21
docs/File.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
# File
|
||||
|
||||
- `v::file()`
|
||||
|
||||
Validates files.
|
||||
|
||||
```php
|
||||
v::file()->validate(__FILE__); //true
|
||||
v::file()->validate(__DIR__); //false
|
||||
```
|
||||
|
||||
This validator will consider SplFileInfo instances, so you can do something like:
|
||||
|
||||
```php
|
||||
v::file()->validate(new \SplFileInfo($file));
|
||||
```
|
||||
|
||||
See also
|
||||
|
||||
* [Directory](Directory.md)
|
||||
* [Exists](Exists.md)
|
15
docs/FilterVar.md
Normal file
15
docs/FilterVar.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# FilterVar
|
||||
|
||||
- `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
|
||||
|
||||
* [Callback](Callback.md)
|
10
docs/Float.md
Normal file
10
docs/Float.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
# Float
|
||||
|
||||
- `v::float()`
|
||||
|
||||
Validates a floating point number.
|
||||
|
||||
```php
|
||||
v::float()->validate(1.5); //true
|
||||
v::float()->validate('1e5'); //true
|
||||
```
|
14
docs/Graph.md
Normal file
14
docs/Graph.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Graph
|
||||
|
||||
- `v::graph()`
|
||||
- `v::graph(string $additionalChars)`
|
||||
|
||||
Validates all characters that are graphically represented.
|
||||
|
||||
```php
|
||||
v::graph()->validate('LKM@#$%4;'); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Prnt](Prnt.md)
|
15
docs/HexRgbColor.md
Normal file
15
docs/HexRgbColor.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# HexRgbColor
|
||||
|
||||
- `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:
|
||||
|
||||
* [Vxdigit](Vxdigit.md)
|
15
docs/INSTALL.md
Normal file
15
docs/INSTALL.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Installation
|
||||
|
||||
Package is available on [Packagist](http://packagist.org/packages/respect/validation),
|
||||
you can install it using [Composer](http://getcomposer.org).
|
||||
|
||||
```shell
|
||||
composer require respect/validation
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
- [Contributing](../CONTRIBUTING.md)
|
||||
- [Feature Guide](README.md)
|
||||
- [License](../LICENSE.md)
|
||||
- [Validators](VALIDATORS.md)
|
29
docs/In.md
Normal file
29
docs/In.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
# In
|
||||
|
||||
- `v::in(mixed $haystack)`
|
||||
- `v::in(mixed $haystack, boolean $identical = false)`
|
||||
|
||||
Validates if the input is contained in a specific haystack.
|
||||
|
||||
For strings:
|
||||
|
||||
```php
|
||||
v::in('lorem ipsum')->validate('ipsum'); //true
|
||||
```
|
||||
|
||||
For arrays:
|
||||
|
||||
```php
|
||||
v::in(array('lorem', 'ipsum'))->validate('lorem'); //true
|
||||
```
|
||||
|
||||
A second parameter may be passed for identical comparison instead
|
||||
of equal comparison.
|
||||
|
||||
Message template for this validator includes `{{haystack}}`.
|
||||
|
||||
See also:
|
||||
|
||||
* [StartsWith](StartsWith.md)
|
||||
* [EndsWith](EndsWith.md)
|
||||
* [Contains](Contains.md)
|
16
docs/Instance.md
Normal file
16
docs/Instance.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Instance
|
||||
|
||||
- `v::instance(string $instanceName)`
|
||||
|
||||
Validates if the input is an instance of the given class or interface.
|
||||
|
||||
```php
|
||||
v::instance('DateTime')->validate(new DateTime); //true
|
||||
v::instance('Traversable')->validate(new ArrayObject); //true
|
||||
```
|
||||
|
||||
Message template for this validator includes `{{instanceName}}`.
|
||||
|
||||
See also:
|
||||
|
||||
* [Object](Object.md)
|
15
docs/Int.md
Normal file
15
docs/Int.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Int
|
||||
|
||||
- `v::int()`
|
||||
|
||||
Validates if the input is an integer.
|
||||
|
||||
```php
|
||||
v::int()->validate('10'); //true
|
||||
v::int()->validate(10); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Numeric](Numeric.md)
|
||||
* [Digit](Digit.md)
|
17
docs/Ip.md
Normal file
17
docs/Ip.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Ip
|
||||
|
||||
- `v::ip()`
|
||||
- `v::ip(mixed $options)`
|
||||
|
||||
Validates IP Addresses. This validator uses the native filter_var()
|
||||
PHP function.
|
||||
|
||||
```php
|
||||
v::ip()->validate('192.168.0.1');
|
||||
```
|
||||
|
||||
You can pass a parameter with filter_var flags for IP.
|
||||
|
||||
```php
|
||||
v::ip(FILTER_FLAG_NO_PRIV_RANGE)->validate('127.0.0.1'); //false
|
||||
```
|
9
docs/Json.md
Normal file
9
docs/Json.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Json
|
||||
|
||||
- `v::json()`
|
||||
|
||||
Validates if the given input is a valid JSON.
|
||||
|
||||
```php
|
||||
v::json()->validate('{"foo":"bar"}'); //true
|
||||
```
|
33
docs/Key.md
Normal file
33
docs/Key.md
Normal file
|
@ -0,0 +1,33 @@
|
|||
# Key
|
||||
|
||||
- `v::key(string $name)`
|
||||
- `v::key(string $name, v $validator)`
|
||||
- `v::key(string $name, v $validator, boolean $mandatory = true)`
|
||||
|
||||
Validates an array key.
|
||||
|
||||
```php
|
||||
$dict = array(
|
||||
'foo' => 'bar'
|
||||
);
|
||||
|
||||
v::key('foo')->validate($dict); //true
|
||||
```
|
||||
|
||||
You can also validate the key value itself:
|
||||
|
||||
```php
|
||||
v::key('foo', v::equals('bar'))->validate($dict); //true
|
||||
```
|
||||
|
||||
Third parameter makes the key presence optional:
|
||||
|
||||
```php
|
||||
v::key('lorem', v::string(), false)->validate($dict); // true
|
||||
```
|
||||
|
||||
The name of this validator is automatically set to the key name.
|
||||
|
||||
See also:
|
||||
|
||||
* [Attribute](Attribute.md)
|
17
docs/LeapDate.md
Normal file
17
docs/LeapDate.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
# LeapDate
|
||||
|
||||
- `v::leapDate(string $format)`
|
||||
|
||||
Validates if a date is leap.
|
||||
|
||||
```php
|
||||
v::leapDate('Y-m-d')->validate('1988-02-29'); //true
|
||||
```
|
||||
|
||||
This validator accepts DateTime instances as well. The $format
|
||||
parameter is mandatory.
|
||||
|
||||
See also:
|
||||
|
||||
* [Date](Date.md)
|
||||
* [LeapYear](LeapYear.md)
|
16
docs/LeapYear.md
Normal file
16
docs/LeapYear.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
# LeapYear
|
||||
|
||||
- `v::leapYear()`
|
||||
|
||||
Validates if a year is leap.
|
||||
|
||||
```php
|
||||
v::leapYear()->validate('1988'); //true
|
||||
```
|
||||
|
||||
This validator accepts DateTime instances as well.
|
||||
|
||||
See also:
|
||||
|
||||
* [Date](Date.md)
|
||||
* [LeapDate](LeapDate.md)
|
43
docs/Length.md
Normal file
43
docs/Length.md
Normal file
|
@ -0,0 +1,43 @@
|
|||
# Length
|
||||
|
||||
- `v::length(int $min, int $max)`
|
||||
- `v::length(int $min, null)`
|
||||
- `v::length(null, int $max)`
|
||||
- `v::length(int $min, int $max, boolean $inclusive = true)`
|
||||
|
||||
Validates lengths. Most simple example:
|
||||
|
||||
```php
|
||||
v::string()->length(1, 5)->validate('abc'); //true
|
||||
```
|
||||
|
||||
You can also validate only minimum length:
|
||||
|
||||
```php
|
||||
v::string()->length(5, null)->validate('abcdef'); // true
|
||||
```
|
||||
|
||||
Only maximum length:
|
||||
|
||||
```php
|
||||
v::string()->length(null, 5)->validate('abc'); // true
|
||||
```
|
||||
|
||||
The type as the first validator in a chain is a good practice,
|
||||
since length accepts many types:
|
||||
|
||||
```php
|
||||
v::arr()->length(1, 5)->validate(array('foo', 'bar')); //true
|
||||
```
|
||||
|
||||
A third parameter may be passed to validate the passed values inclusive:
|
||||
|
||||
```php
|
||||
v::string()->length(1, 5, true)->validate('a'); //true
|
||||
```
|
||||
|
||||
Message template for this validator includes `{{minValue}}` and `{{maxValue}}`.
|
||||
|
||||
See also:
|
||||
|
||||
* [Between](Between.md)
|
13
docs/Lowercase.md
Normal file
13
docs/Lowercase.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Lowercase
|
||||
|
||||
- `v::lowercase()`
|
||||
|
||||
Validates if string characters are lowercase in the input:
|
||||
|
||||
```php
|
||||
v::string()->lowercase()->validate('xkcd'); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Uppercase](Uppercase.md)
|
10
docs/MacAddress.md
Normal file
10
docs/MacAddress.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
# MacAddress
|
||||
|
||||
- `v::macAddress()`
|
||||
|
||||
Validates a Mac Address.
|
||||
|
||||
```php
|
||||
v::macAddress()->validate('00:11:22:33:44:55'); //true
|
||||
v::macAddress()->validate('af-AA-22-33-44-55'); //true
|
||||
```
|
35
docs/Max.md
Normal file
35
docs/Max.md
Normal file
|
@ -0,0 +1,35 @@
|
|||
# Max
|
||||
|
||||
- `v::max(mixed $maxValue)`
|
||||
- `v::max(mixed $maxValue, boolean $inclusive = false)`
|
||||
|
||||
Validates if the input doesn't exceed the maximum value.
|
||||
|
||||
```php
|
||||
v::int()->max(15)->validate(20); //false
|
||||
v::int()->max(20)->validate(20); //false
|
||||
v::int()->max(20, true)->validate(20); //true
|
||||
```
|
||||
|
||||
Also accepts dates:
|
||||
|
||||
```php
|
||||
v::date()->max('2012-01-01')->validate('2010-01-01'); //true
|
||||
```
|
||||
|
||||
Also date intervals:
|
||||
|
||||
```php
|
||||
// Same of minimum age validation
|
||||
v::date()->max('-18 years')->validate('1988-09-09'); //true
|
||||
```
|
||||
|
||||
`true` may be passed as a parameter to indicate that inclusive
|
||||
values must be used.
|
||||
|
||||
Message template for this validator includes `{{maxValue}}`.
|
||||
|
||||
See also:
|
||||
|
||||
* [Min](Min.md)
|
||||
* [Between](Between.md)
|
28
docs/Min.md
Normal file
28
docs/Min.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
# Min
|
||||
|
||||
- `v::min(mixed $minValue)`
|
||||
- `v::min(mixed $minValue, boolean $inclusive = false)`
|
||||
|
||||
Validates if the input is greater than the minimum value.
|
||||
|
||||
```php
|
||||
v::int()->min(15)->validate(5); //false
|
||||
v::int()->min(5)->validate(5); //false
|
||||
v::int()->min(5, true)->validate(5); //true
|
||||
```
|
||||
|
||||
Also accepts dates:
|
||||
|
||||
```php
|
||||
v::date()->min('2012-01-01')->validate('2015-01-01'); //true
|
||||
```
|
||||
|
||||
`true` may be passed as a parameter to indicate that inclusive
|
||||
values must be used.
|
||||
|
||||
Message template for this validator includes `{{minValue}}`.
|
||||
|
||||
See also:
|
||||
|
||||
* [Max](Max.md)
|
||||
* [Between](Between.md)
|
19
docs/MinimumAge.md
Normal file
19
docs/MinimumAge.md
Normal file
|
@ -0,0 +1,19 @@
|
|||
# MinimumAge
|
||||
|
||||
- `v::minimumAge(int $age)`
|
||||
- `v::minimumAge(int $age, string $format)`
|
||||
|
||||
Validates a minimum age for a given date.
|
||||
|
||||
```php
|
||||
v::minimumAge(18)->validate('1987-01-01'); //true
|
||||
v::minimumAge(18, 'd/m/Y')->validate('01/01/1987'); //true
|
||||
```
|
||||
|
||||
Using `date()` before is a best-practice.
|
||||
|
||||
Message template for this validator includes `{{age}}`.
|
||||
|
||||
See also:
|
||||
|
||||
* [Date](Date.md)
|
13
docs/Multiple.md
Normal file
13
docs/Multiple.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Multiple
|
||||
|
||||
- `v::multiple(int $multipleOf)`
|
||||
|
||||
Validates if the input is a multiple of the given parameter
|
||||
|
||||
```php
|
||||
v::int()->multiple(3)->validate(9); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [PrimeNumber](PrimeNumber.md)
|
13
docs/Negative.md
Normal file
13
docs/Negative.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Negative
|
||||
|
||||
- `v::negative()`
|
||||
|
||||
Validates if a number is lower than zero
|
||||
|
||||
```php
|
||||
v::numeric()->negative()->validate(-15); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Positive](Positive.md)
|
9
docs/NfeAccessKey.md
Normal file
9
docs/NfeAccessKey.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# NfeAccessKey
|
||||
|
||||
- `v::nfeAccessKey(string $accessKey)`
|
||||
|
||||
Validates the access key of the Brazilian electronic invoice (NFe).
|
||||
|
||||
```php
|
||||
v::nfeAccessKey()->validate('31841136830118868211870485416765268625116906'); //true
|
||||
```
|
23
docs/No.md
Normal file
23
docs/No.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
# No
|
||||
|
||||
- `v::no()`
|
||||
- `v::no(boolean $locale)`
|
||||
|
||||
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 `$locale` is TRUE, uses the value of [nl_langinfo()](http://php.net/nl_langinfo) with `NOEXPR` constant.
|
||||
|
||||
See also:
|
||||
|
||||
* [Yes](Yes.md)
|
19
docs/NoWhitespace.md
Normal file
19
docs/NoWhitespace.md
Normal file
|
@ -0,0 +1,19 @@
|
|||
# NoWhitespace
|
||||
|
||||
- `v::noWhitespace()`
|
||||
|
||||
Validates if a string contains no whitespace (spaces, tabs and line breaks);
|
||||
|
||||
```php
|
||||
v::noWhitespace()->validate('foo bar'); //false
|
||||
v::noWhitespace()->validate("foo\nbar"); //false
|
||||
```
|
||||
|
||||
Like other rules the input is still optional.
|
||||
|
||||
```php
|
||||
v::string()->noWhitespace()->validate(''); //true
|
||||
v::string()->noWhitespace()->validate(' '); //false
|
||||
```
|
||||
|
||||
This is most useful when chaining with other validators such as `v::alnum()`
|
20
docs/NoneOf.md
Normal file
20
docs/NoneOf.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
# NoneOf
|
||||
|
||||
- `v::noneOf(v $v1, v $v2, v $v3...)`
|
||||
|
||||
Validates if NONE of the given validators validate:
|
||||
|
||||
```php
|
||||
v::noneOf(
|
||||
v::int(),
|
||||
v::float()
|
||||
)->validate('foo'); //true
|
||||
```
|
||||
|
||||
In the sample above, 'foo' isn't a integer nor a float, so noneOf returns true.
|
||||
|
||||
See also:
|
||||
|
||||
* [Not](Not.md)
|
||||
* [AllOf](AllOf.md)
|
||||
* [OneOf](OneOf.md)
|
35
docs/Not.md
Normal file
35
docs/Not.md
Normal file
|
@ -0,0 +1,35 @@
|
|||
# Not
|
||||
|
||||
- `v::not(v $negatedValidator)`
|
||||
|
||||
Negates any rule.
|
||||
|
||||
```php
|
||||
v::not(v::ip())->validate('foo'); //true
|
||||
```
|
||||
|
||||
using a shortcut
|
||||
|
||||
```php
|
||||
v::ip()->not()->validate('foo'); //true
|
||||
```
|
||||
|
||||
In the sample above, validator returns true because 'foo' isn't an IP Address.
|
||||
|
||||
You can negate complex, grouped or chained validators as well:
|
||||
|
||||
```php
|
||||
v::not(v::int()->positive())->validate(-1.5); //true
|
||||
```
|
||||
|
||||
using a shortcut
|
||||
|
||||
```php
|
||||
v::int()->positive()->not()->validate(-1.5); //true
|
||||
```
|
||||
|
||||
Each other validation has custom messages for negated rules.
|
||||
|
||||
See also:
|
||||
|
||||
* [NoneOf](NoneOf.md)
|
41
docs/NotEmpty.md
Normal file
41
docs/NotEmpty.md
Normal file
|
@ -0,0 +1,41 @@
|
|||
# NotEmpty
|
||||
|
||||
- `v::notEmpty()`
|
||||
|
||||
Validates if the given input is not empty or in other words is input mandatory and
|
||||
required. This function also takes whitespace into account, use `noWhitespace()`
|
||||
if no spaces or linebreaks and other whitespace anywhere in the input is desired.
|
||||
|
||||
```php
|
||||
v::string()->notEmpty()->validate(''); //false
|
||||
```
|
||||
|
||||
Null values are empty:
|
||||
|
||||
```php
|
||||
v::notEmpty()->validate(null); //false
|
||||
```
|
||||
|
||||
Numbers:
|
||||
|
||||
```php
|
||||
v::int()->notEmpty()->validate(0); //false
|
||||
```
|
||||
|
||||
Empty arrays:
|
||||
|
||||
```php
|
||||
v::arr()->notEmpty()->validate(array()); //false
|
||||
```
|
||||
|
||||
Whitespace:
|
||||
|
||||
```php
|
||||
v::string()->notEmpty()->validate(' '); //false
|
||||
v::string()->notEmpty()->validate("\t \n \r"); //false
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [NoWhitespace](NoWhitespace.md)
|
||||
* [NullValue](NullValue.md)
|
13
docs/NullValue.md
Normal file
13
docs/NullValue.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# NullValue
|
||||
|
||||
- `v::nullValue()`
|
||||
|
||||
Validates if the input is null. This rule does not allow empty strings to avoid ambiguity.
|
||||
|
||||
```php
|
||||
v::nullValue()->validate(null); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [NotEmpty](NotEmpty.md)
|
15
docs/Numeric.md
Normal file
15
docs/Numeric.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Numeric
|
||||
|
||||
- `v::numeric()`
|
||||
|
||||
Validates on any numeric value.
|
||||
|
||||
```php
|
||||
v::numeric()->validate(-12); //true
|
||||
v::numeric()->validate('135.0'); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Int](Int.md)
|
||||
* [Digit](Digit.md)
|
14
docs/Object.md
Normal file
14
docs/Object.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Object
|
||||
|
||||
- `v::object()`
|
||||
|
||||
Validates if the input is an object.
|
||||
|
||||
```php
|
||||
v::object()->validate(new stdClass); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Instance](Instance.md)
|
||||
* [Attribute](Attribute.md)
|
16
docs/Odd.md
Normal file
16
docs/Odd.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Odd
|
||||
|
||||
- `v::odd()`
|
||||
|
||||
Validates an odd number.
|
||||
|
||||
```php
|
||||
v::int()->odd()->validate(3); //true
|
||||
```
|
||||
|
||||
Using `int()` before `odd()` is a best practice.
|
||||
|
||||
See also
|
||||
|
||||
* [Even](Even.md)
|
||||
* [Multiple](Multiple.md)
|
30
docs/OneOf.md
Normal file
30
docs/OneOf.md
Normal file
|
@ -0,0 +1,30 @@
|
|||
# OneOf
|
||||
|
||||
- `v::oneOf(v $v1, v $v2, v $v3...)`
|
||||
|
||||
This is a group validator that acts as an OR operator.
|
||||
|
||||
```php
|
||||
v::oneOf(
|
||||
v::int(),
|
||||
v::float()
|
||||
)->validate(15.5); //true
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
Using a shortcut
|
||||
|
||||
```php
|
||||
v::int()->addOr(v::float())->validate(15.5); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [AllOf](AllOf.md)
|
||||
* [NoneOf](NoneOf.md)
|
||||
* [When](When.md)
|
10
docs/PerfectSquare.md
Normal file
10
docs/PerfectSquare.md
Normal file
|
@ -0,0 +1,10 @@
|
|||
# PerfectSquare
|
||||
|
||||
- `v::perfectSquare()`
|
||||
|
||||
Validates a perfect square.
|
||||
|
||||
```php
|
||||
v::perfectSquare()->validate(25); //true (5*5)
|
||||
v::perfectSquare()->validate(9); //true (3*3)
|
||||
```
|
15
docs/Phone.md
Normal file
15
docs/Phone.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# Phone
|
||||
|
||||
- `v::phone()`
|
||||
|
||||
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,
|
||||
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
|
13
docs/Positive.md
Normal file
13
docs/Positive.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Positive
|
||||
|
||||
- `v::positive()`
|
||||
|
||||
Validates if a number is higher than zero
|
||||
|
||||
```php
|
||||
v::numeric()->positive()->validate(-15); //false
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Negative](Negative.md)
|
17
docs/PostalCode.md
Normal file
17
docs/PostalCode.md
Normal file
|
@ -0,0 +1,17 @@
|
|||
# PostalCode
|
||||
|
||||
- `v::postalCode(string $countryCode)`
|
||||
|
||||
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:
|
||||
|
||||
* [CountryCode](CountryCode.md)
|
9
docs/PrimeNumber.md
Normal file
9
docs/PrimeNumber.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# PrimeNumber
|
||||
|
||||
- `v::primeNumber()`
|
||||
|
||||
Validates a prime number
|
||||
|
||||
```php
|
||||
v::primeNumber()->validate(7); //true
|
||||
```
|
14
docs/Prnt.md
Normal file
14
docs/Prnt.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Prnt
|
||||
|
||||
- `v::prnt()`
|
||||
- `v::prnt(string $additionalChars)`
|
||||
|
||||
Similar to `v::graph` but accepts whitespace.
|
||||
|
||||
```php
|
||||
v::prnt()->validate('LMKA0$% _123'); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Graph](Graph.md)
|
16
docs/Punct.md
Normal file
16
docs/Punct.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Punct
|
||||
|
||||
- `v::punct()`
|
||||
- `v::punct(string $additionalChars)`
|
||||
|
||||
Accepts only punctuation characters:
|
||||
|
||||
```php
|
||||
v::punct()->validate('&,.;[]'); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Cntrl](Cntrl.md)
|
||||
* [Graph](Graph.md)
|
||||
* [Prnt](Prnt.md)
|
214
docs/README.md
Normal file
214
docs/README.md
Normal file
|
@ -0,0 +1,214 @@
|
|||
# Feature Guide
|
||||
|
||||
## Namespace Import
|
||||
|
||||
Respect\Validation is namespaced, but you can make your life easier by importing
|
||||
a single class into your context:
|
||||
|
||||
```php
|
||||
use Respect\Validation\Validator as v;
|
||||
```
|
||||
|
||||
## Simple Validation
|
||||
|
||||
The Hello World validator is something like this:
|
||||
|
||||
```php
|
||||
$number = 123;
|
||||
v::numeric()->validate($number); //true
|
||||
```
|
||||
|
||||
## Chained Validation
|
||||
|
||||
It is possible to use validators in a chain. Sample below validates a string
|
||||
containing numbers and letters, no whitespace and length between 1 and 15.
|
||||
|
||||
```php
|
||||
$usernameValidator = v::alnum()->noWhitespace()->length(1,15);
|
||||
$usernameValidator->validate('alganet'); //true
|
||||
```
|
||||
|
||||
## Validating Object Attributes
|
||||
|
||||
Given this simple object:
|
||||
|
||||
```php
|
||||
$user = new stdClass;
|
||||
$user->name = 'Alexandre';
|
||||
$user->birthdate = '1987-07-01';
|
||||
```
|
||||
|
||||
Is possible to validate its attributes in a single chain:
|
||||
|
||||
```php
|
||||
$userValidator = v::attribute('name', v::string()->length(1,32))
|
||||
->attribute('birthdate', v::date()->minimumAge(18));
|
||||
|
||||
$userValidator->validate($user); //true
|
||||
```
|
||||
|
||||
Validating array keys is also possible using `v::key()`
|
||||
|
||||
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.
|
||||
|
||||
## Input optional
|
||||
|
||||
All validators treat input as optional and will accept empty string input as valid,
|
||||
unless otherwise stated in the documentation.
|
||||
|
||||
We use the `v:notEmpty()` validator prefixed to disallow empty input and effectively
|
||||
define the field as mandatory as input will be required or validation will fail.
|
||||
|
||||
```php
|
||||
v::string()->notEmpty()->validate(''); //false input required
|
||||
```
|
||||
|
||||
## Negating Rules
|
||||
|
||||
You can use the `v::not()` to negate any rule:
|
||||
|
||||
```php
|
||||
v::not(v::int())->validate(10); //false, input must not be integer
|
||||
```
|
||||
|
||||
## Validator Reuse
|
||||
|
||||
Once created, you can reuse your validator anywhere. Remember $usernameValidator?
|
||||
|
||||
```php
|
||||
$usernameValidator->validate('respect'); //true
|
||||
$usernameValidator->validate('alexandre gaigalas'); //false
|
||||
$usernameValidator->validate('#$%'); //false
|
||||
```
|
||||
|
||||
## Exception Types
|
||||
|
||||
* `Repect\Validation\Exceptions\ExceptionInterface`:
|
||||
* All exceptions implement this interface;
|
||||
* `Respect\Validation\Exceptions\ValidationExceptionInterface`:
|
||||
* Extends the `Repect\Validation\Exceptions\ExceptionInterface` interface
|
||||
* Use when calling `check()`
|
||||
* All validation exceptions implement this interface
|
||||
* Interface has one method: `getMainMessage()`
|
||||
* `Respect\Validation\Exceptions\NestedValidationExceptionInterface`:
|
||||
* Extends the `Respect\Validation\Exceptions\ValidationExceptionInterface` interface
|
||||
* Use when calling `assert()`
|
||||
* Interface has three methods: `getFullMessage()`, `findMessages()`, and `getMainMessage()`.
|
||||
|
||||
## Informative Exceptions
|
||||
|
||||
When something goes wrong, Validation can tell you exactly what's going on. For this,
|
||||
we use the `assert()` method instead of `validate()`:
|
||||
|
||||
```php
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface
|
||||
|
||||
try {
|
||||
$usernameValidator->assert('really messed up screen#name');
|
||||
} catch(NestedValidationExceptionInterface $exception) {
|
||||
echo $exception->getFullMessage();
|
||||
}
|
||||
```
|
||||
|
||||
The printed message is exactly this, as a text tree:
|
||||
|
||||
\-All of the 3 required rules must pass
|
||||
|-"really messed up screen#name" must contain only letters (a-z) and digits (0-9)
|
||||
|-"really messed up screen#name" must not contain whitespace
|
||||
\-"really messed up screen#name" must have a length between 1 and 15
|
||||
|
||||
## Getting Messages
|
||||
|
||||
The text tree is fine, but unusable on a HTML form or something more custom. You can use
|
||||
`findMessages()` for that:
|
||||
|
||||
```php
|
||||
use Respect\Validation\Exceptions\NestedValidationExceptionInterface
|
||||
|
||||
try {
|
||||
$usernameValidator->assert('really messed up screen#name');
|
||||
} catch(NestedValidationExceptionInterface $exception) {
|
||||
var_dump($exception->findMessages(array('alnum', 'length', 'noWhitespace')));
|
||||
}
|
||||
```
|
||||
|
||||
`findMessages()` returns an array with messages from the requested validators.
|
||||
|
||||
## Custom Messages
|
||||
|
||||
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:
|
||||
|
||||
```php
|
||||
$errors = $exception->findMessages(array(
|
||||
'alnum' => '{{name}} must contain only letters and digits',
|
||||
'length' => '{{name}} must not have more than 15 chars',
|
||||
'noWhitespace' => '{{name}} cannot contain spaces'
|
||||
));
|
||||
```
|
||||
|
||||
For all messages, the `{{name}}` and `{{input}}` variable is available for templates.
|
||||
|
||||
## Custom Rules
|
||||
|
||||
You also can use your own rules:
|
||||
|
||||
```php
|
||||
v::with('My\\Validation\\Rules\\');
|
||||
v::myRule(); // Try to load "My\Validation\Rules\MyRule" if any
|
||||
```
|
||||
|
||||
By default `with()` appends the given prefix, but you can change this behavior
|
||||
in order to overwrite default rules:
|
||||
|
||||
```php
|
||||
v::with('My\\Validation\\Rules\\', true);
|
||||
v::alnum(); // Try to use "My\Validation\Rules\Alnum" if any
|
||||
```
|
||||
|
||||
## Validator Name
|
||||
|
||||
On `v::attribute()` and `v::key()`, `{{name}}` is the attribute/key name. For others,
|
||||
is the same as the input. You can customize a validator name using:
|
||||
|
||||
```php
|
||||
v::date('Y-m-d')->between('1980-02-02', 'now')->setName('Member Since');
|
||||
```
|
||||
|
||||
## Zend/Symfony Validators
|
||||
|
||||
It is also possible to reuse validators from other frameworks if they are installed:
|
||||
|
||||
```php
|
||||
$hostnameValidator = v::zend('Hostname')->assert('google.com');
|
||||
$timeValidator = v::sf('Time')->assert('22:00:01');
|
||||
```
|
||||
|
||||
## Validation Methods
|
||||
|
||||
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:
|
||||
|
||||
```php
|
||||
use Respect\Validation\Exceptions\ValidationExceptionInterface
|
||||
|
||||
try {
|
||||
$usernameValidator->check('really messed up screen#name');
|
||||
} catch(ValidationExceptionInterface $exception) {
|
||||
echo $exception->getMainMessage();
|
||||
}
|
||||
```
|
||||
|
||||
Message:
|
||||
|
||||
"really messed up screen#name" must contain only letters (a-z) and digits (0-9)
|
||||
|
||||
See also:
|
||||
|
||||
- [Contributing](../CONTRIBUTING.md)
|
||||
- [Installation](INSTALL.md)
|
||||
- [License](../LICENSE.md)
|
||||
- [Validators](VALIDATORS.md)
|
9
docs/Readable.md
Normal file
9
docs/Readable.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Readable
|
||||
|
||||
- `v::readable()`
|
||||
|
||||
Validates if the given data is a file exists and is readable.
|
||||
|
||||
```php
|
||||
v::readable()->validate('/path/of/a/readable/file'); //true
|
||||
```
|
11
docs/Regex.md
Normal file
11
docs/Regex.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Regex
|
||||
|
||||
- `v::regex(string $regex)`
|
||||
|
||||
Evaluates a regex on the input and validates if matches
|
||||
|
||||
```php
|
||||
v::regex('/[a-z]/')->validate('a'); //true
|
||||
```
|
||||
|
||||
Message template for this validator includes `{{regex}}`
|
12
docs/Roman.md
Normal file
12
docs/Roman.md
Normal file
|
@ -0,0 +1,12 @@
|
|||
# Roman
|
||||
|
||||
- `v::roman()`
|
||||
|
||||
Validates roman numbers
|
||||
|
||||
```php
|
||||
v::roman()->validate('IV'); //true
|
||||
```
|
||||
|
||||
This validator ignores empty values, use `notEmpty()` when
|
||||
appropriate.
|
18
docs/Sf.md
Normal file
18
docs/Sf.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Sf
|
||||
|
||||
- `v::sf(string $validator)`
|
||||
|
||||
Use Symfony2 validators inside Respect\Validation flow. Messages
|
||||
are preserved.
|
||||
|
||||
```php
|
||||
v::sf('Time')->validate('15:00:00');
|
||||
```
|
||||
|
||||
|
||||
You must add `"symfony/validator": "~2.6"` to your `require` property on composer.json file.
|
||||
|
||||
|
||||
See also:
|
||||
|
||||
* [Zend](Zend.md)
|
11
docs/Slug.md
Normal file
11
docs/Slug.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Slug
|
||||
|
||||
- `v::slug()`
|
||||
|
||||
Validates slug-like strings:
|
||||
|
||||
```php
|
||||
v::slug()->validate('my-wordpress-title'); //true
|
||||
v::slug()->validate('my-wordpress--title'); //false
|
||||
v::slug()->validate('my-wordpress-title-'); //false
|
||||
```
|
14
docs/Space.md
Normal file
14
docs/Space.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Space
|
||||
|
||||
- `v::space()`
|
||||
- `v::space(string $additionalChars)`
|
||||
|
||||
Accepts only whitespace:
|
||||
|
||||
```php
|
||||
v::space()->validate(' '); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Cntrl](Cntrl.md)
|
30
docs/StartsWith.md
Normal file
30
docs/StartsWith.md
Normal file
|
@ -0,0 +1,30 @@
|
|||
# StartsWith
|
||||
|
||||
- `v::startsWith(mixed $value)`
|
||||
- `v::startsWith(mixed $value, boolean $identical = false)`
|
||||
|
||||
This validator is similar to `v::contains()`, but validates
|
||||
only if the value is at the beginning of the input.
|
||||
|
||||
For strings:
|
||||
|
||||
```php
|
||||
v::startsWith('lorem')->validate('lorem ipsum'); //true
|
||||
```
|
||||
|
||||
For arrays:
|
||||
|
||||
```php
|
||||
v::startsWith('lorem')->validate(array('lorem', 'ipsum')); //true
|
||||
```
|
||||
|
||||
`true` may be passed as a parameter to indicate identical comparison
|
||||
instead of equal.
|
||||
|
||||
Message template for this validator includes `{{startValue}}`.
|
||||
|
||||
See also:
|
||||
|
||||
* [EndsWith](EndsWith.md)
|
||||
* [Contains](Contains.md)
|
||||
* [In](In.md)
|
13
docs/String.md
Normal file
13
docs/String.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# String
|
||||
|
||||
- `v::string()`
|
||||
|
||||
Validates a string.
|
||||
|
||||
```php
|
||||
v::string()->validate('hi'); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Alnum](Alnum.md)
|
9
docs/SymbolicLink.md
Normal file
9
docs/SymbolicLink.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# SymbolicLink
|
||||
|
||||
- `v::symbolicLink()`
|
||||
|
||||
Validates if the given data is a path of a valid symbolic link.
|
||||
|
||||
```php
|
||||
v::symbolicLink()->validate('/path/of/valid/symbolic/link'); //true
|
||||
```
|
16
docs/Tld.md
Normal file
16
docs/Tld.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Tld
|
||||
|
||||
- `v::tld()`
|
||||
|
||||
Validates a top-level domain
|
||||
|
||||
```php
|
||||
v::tld()->validate('com'); //true
|
||||
v::tld()->validate('ly'); //true
|
||||
v::tld()->validate('org'); //true
|
||||
```
|
||||
|
||||
See also
|
||||
|
||||
* [Domain](Domain.md)
|
||||
* [CountryCode](CountryCode.md)
|
18
docs/True.md
Normal file
18
docs/True.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
# True
|
||||
|
||||
- `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
|
||||
```
|
||||
|
||||
See also
|
||||
|
||||
* [False](False.md)
|
21
docs/Type.md
Normal file
21
docs/Type.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Type
|
||||
|
||||
- `v::type(string $type)`
|
||||
|
||||
Validates the type of input.
|
||||
|
||||
```php
|
||||
v::type('bool')->validate(true); //true
|
||||
v::type('callable')->validate(function (){}); //true
|
||||
v::type('object')->validate(new stdClass()); //true
|
||||
```
|
||||
|
||||
See also
|
||||
|
||||
* [Arr](Arr.md)
|
||||
* [Bool](Bool.md)
|
||||
* [Float](Float.md)
|
||||
* [Instance](Instance.md)
|
||||
* [Int](Int.md)
|
||||
* [Object](Object.md)
|
||||
* [String](String.md)
|
9
docs/Uploaded.md
Normal file
9
docs/Uploaded.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Uploaded
|
||||
|
||||
- `v::uploaded()`
|
||||
|
||||
Validates if the given data is a file that was uploaded via HTTP POST.
|
||||
|
||||
```php
|
||||
v::uploaded()->validate('/path/of/an/uploaded/file'); //true
|
||||
```
|
13
docs/Uppercase.md
Normal file
13
docs/Uppercase.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Uppercase
|
||||
|
||||
- `v::uppercase()`
|
||||
|
||||
Validates if string characters are uppercase in the input:
|
||||
|
||||
```php
|
||||
v::string()->uppercase()->validate('W3C'); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Lowercase](Lowercase.md)
|
20
docs/Url.md
Normal file
20
docs/Url.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
# Url
|
||||
|
||||
- `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 [FilterVar](FilterVar.md)
|
||||
|
||||
See also:
|
||||
|
||||
* [Domain](Domain.md)
|
||||
* [FilterVar](FilterVar.md)
|
265
docs/VALIDATORS.md
Normal file
265
docs/VALIDATORS.md
Normal file
|
@ -0,0 +1,265 @@
|
|||
# Validators
|
||||
|
||||
## Types
|
||||
|
||||
* [Arr](Arr.md)
|
||||
* [Bool](Bool.md)
|
||||
* [Date](Date.md)
|
||||
* [False](False.md)
|
||||
* [Float](Float.md)
|
||||
* [Instance](Instance.md)
|
||||
* [Int](Int.md)
|
||||
* [NullValue](NullValue.md)
|
||||
* [Numeric](Numeric.md)
|
||||
* [Object](Object.md)
|
||||
* [String](String.md)
|
||||
* [True](True.md)
|
||||
* [Type](Type.md)
|
||||
* [Xdigit](Xdigit.md)
|
||||
|
||||
## Generics
|
||||
|
||||
* [AlwaysInvalid](AlwaysInvalid.md)
|
||||
* [AlwaysValid](AlwaysValid.md)
|
||||
* [Call](Call.md)
|
||||
* [Callback](Callback.md)
|
||||
* [FilterVar](FilterVar.md)
|
||||
* [Not](Not.md)
|
||||
* [Type](Type.md)
|
||||
* [When](When.md)
|
||||
|
||||
## Comparing Values
|
||||
|
||||
* [Between](Between.md)
|
||||
* [Equals](Equals.md)
|
||||
* [Max](Max.md)
|
||||
* [Min](Min.md)
|
||||
|
||||
## Numeric
|
||||
|
||||
* [Between](Between.md)
|
||||
* [Bool](Bool.md)
|
||||
* [Even](Even.md)
|
||||
* [Float](Float.md)
|
||||
* [Int](Int.md)
|
||||
* [Multiple](Multiple.md)
|
||||
* [Negative](Negative.md)
|
||||
* [NotEmpty](NotEmpty.md)
|
||||
* [Numeric](Numeric.md)
|
||||
* [Odd](Odd.md)
|
||||
* [PerfectSquare](PerfectSquare.md)
|
||||
* [Positive](Positive.md)
|
||||
* [PrimeNumber](PrimeNumber.md)
|
||||
* [Roman](Roman.md)
|
||||
* [Xdigit](Xdigit.md)
|
||||
|
||||
## String
|
||||
|
||||
* [Alnum](Alnum.md)
|
||||
* [Alpha](Alpha.md)
|
||||
* [Between](Between.md)
|
||||
* [Charset](Charset.md)
|
||||
* [Cntrl](Cntrl.md)
|
||||
* [Consonant](Consonant.md)
|
||||
* [Contains](Contains.md)
|
||||
* [Digit](Digit.md)
|
||||
* [EndsWith](EndsWith.md)
|
||||
* [Graph](Graph.md)
|
||||
* [In](In.md)
|
||||
* [Length](Length.md)
|
||||
* [Lowercase](Lowercase.md)
|
||||
* [NotEmpty](NotEmpty.md)
|
||||
* [NoWhitespace](NoWhitespace.md)
|
||||
* [Prnt](Prnt.md)
|
||||
* [Punct](Punct.md)
|
||||
* [Regex](Regex.md)
|
||||
* [Slug](Slug.md)
|
||||
* [Space](Space.md)
|
||||
* [StartsWith](StartsWith.md)
|
||||
* [Uppercase](Uppercase.md)
|
||||
* [Version](Version.md)
|
||||
* [Vowel](Vowel.md)
|
||||
* [Xdigit](Xdigit.md)
|
||||
|
||||
## Arrays
|
||||
|
||||
* [Arr](Arr.md)
|
||||
* [Contains](Contains.md)
|
||||
* [Each](Each.md)
|
||||
* [EndsWith](EndsWith.md)
|
||||
* [In](In.md)
|
||||
* [Key](Key.md)
|
||||
* [Length](Length.md)
|
||||
* [NotEmpty](NotEmpty.md)
|
||||
* [StartsWith](StartsWith.md)
|
||||
|
||||
## Objects
|
||||
|
||||
* [Attribute](Attribute.md)
|
||||
* [Instance](Instance.md)
|
||||
* [Length](Length.md)
|
||||
|
||||
## Date and Time
|
||||
|
||||
* [Between](Between.md)
|
||||
* [Date](Date.md)
|
||||
* [LeapDate](LeapDate.md)
|
||||
* [LeapYear](LeapYear.md)
|
||||
* [MinimumAge](MinimumAge.md)
|
||||
|
||||
## Group Validators
|
||||
|
||||
* [AllOf](AllOf.md)
|
||||
* [NoneOf](NoneOf.md)
|
||||
* [OneOf](OneOf.md)
|
||||
|
||||
## Regional
|
||||
|
||||
* [CountryCode](CountryCode.md)
|
||||
* [PostalCode](PostalCode.md)
|
||||
* [Tld](Tld.md)
|
||||
|
||||
## Files
|
||||
|
||||
* [Directory](Directory.md)
|
||||
* [Executable](Executable.md)
|
||||
* [Exists](Exists.md)
|
||||
* [File](File.md)
|
||||
* [Readable](Readable.md)
|
||||
* [SymbolicLink](SymbolicLink.md)
|
||||
* [Uploaded](Uploaded.md)
|
||||
* [Writable](Writable.md)
|
||||
|
||||
## Banking
|
||||
|
||||
* [Bank](Bank.md)
|
||||
* [BankAccount](BankAccount.md)
|
||||
* [Bic](Bic.md)
|
||||
|
||||
## Other
|
||||
|
||||
* [Cnh](Cnh.md)
|
||||
* [Cnpj](Cnpj.md)
|
||||
* [Cpf](Cpf.md)
|
||||
* [Domain](Domain.md)
|
||||
* [Email](Email.md)
|
||||
* [HexRgbColor](HexRgbColor.md)
|
||||
* [Ip](Ip.md)
|
||||
* [Json](Json.md)
|
||||
* [MacAddress](MacAddress.md)
|
||||
* [NfeAccessKey](NfeAccessKey.md)
|
||||
* [Phone](Phone.md)
|
||||
* [Sf](Sf.md)
|
||||
* [Url](Url.md)
|
||||
* [Zend](Zend.md)
|
||||
|
||||
## Yes/No
|
||||
|
||||
* [No](No.md)
|
||||
* [Yes](Yes.md)
|
||||
|
||||
## Alphabetically
|
||||
|
||||
* [AllOf](AllOf.md)
|
||||
* [Alnum](Alnum.md)
|
||||
* [Alpha](Alpha.md)
|
||||
* [AlwaysInvalid](AlwaysInvalid.md)
|
||||
* [AlwaysValid](AlwaysValid.md)
|
||||
* [Arr](Arr.md)
|
||||
* [Attribute](Attribute.md)
|
||||
* [Bank](Bank.md)
|
||||
* [BankAccount](BankAccount.md)
|
||||
* [Between](Between.md)
|
||||
* [Bic](Bic.md)
|
||||
* [Bool](Bool.md)
|
||||
* [Call](Call.md)
|
||||
* [Callback](Callback.md)
|
||||
* [Charset](Charset.md)
|
||||
* [Cnh](Cnh.md)
|
||||
* [Cnpj](Cnpj.md)
|
||||
* [Cntrl](Cntrl.md)
|
||||
* [Consonant](Consonant.md)
|
||||
* [Contains](Contains.md)
|
||||
* [CountryCode](CountryCode.md)
|
||||
* [Cpf](Cpf.md)
|
||||
* [CreditCard](CreditCard.md)
|
||||
* [Date](Date.md)
|
||||
* [Digit](Digit.md)
|
||||
* [Directory](Directory.md)
|
||||
* [Domain](Domain.md)
|
||||
* [Each](Each.md)
|
||||
* [Email](Email.md)
|
||||
* [EndsWith](EndsWith.md)
|
||||
* [Equals](Equals.md)
|
||||
* [Even](Even.md)
|
||||
* [Executable](Executable.md)
|
||||
* [Exists](Exists.md)
|
||||
* [False](False.md)
|
||||
* [File](File.md)
|
||||
* [FilterVar](FilterVar.md)
|
||||
* [Float](Float.md)
|
||||
* [Graph](Graph.md)
|
||||
* [HexRgbColor](HexRgbColor.md)
|
||||
* [In](In.md)
|
||||
* [Instance](Instance.md)
|
||||
* [Int](Int.md)
|
||||
* [Ip](Ip.md)
|
||||
* [Json](Json.md)
|
||||
* [Key](Key.md)
|
||||
* [LeapDate](LeapDate.md)
|
||||
* [LeapYear](LeapYear.md)
|
||||
* [Length](Length.md)
|
||||
* [Lowercase](Lowercase.md)
|
||||
* [MacAddress](MacAddress.md)
|
||||
* [Max](Max.md)
|
||||
* [Min](Min.md)
|
||||
* [MinimumAge](MinimumAge.md)
|
||||
* [Multiple](Multiple.md)
|
||||
* [Negative](Negative.md)
|
||||
* [NfeAccessKey](NfeAccessKey.md)
|
||||
* [No](No.md)
|
||||
* [NoWhitespace](NoWhitespace.md)
|
||||
* [NoneOf](NoneOf.md)
|
||||
* [Not](Not.md)
|
||||
* [NotEmpty](NotEmpty.md)
|
||||
* [NullValue](NullValue.md)
|
||||
* [Numeric](Numeric.md)
|
||||
* [Object](Object.md)
|
||||
* [Odd](Odd.md)
|
||||
* [OneOf](OneOf.md)
|
||||
* [PerfectSquare](PerfectSquare.md)
|
||||
* [Phone](Phone.md)
|
||||
* [Positive](Positive.md)
|
||||
* [PostalCode](PostalCode.md)
|
||||
* [PrimeNumber](PrimeNumber.md)
|
||||
* [Prnt](Prnt.md)
|
||||
* [Punct](Punct.md)
|
||||
* [Readable](Readable.md)
|
||||
* [Regex](Regex.md)
|
||||
* [Roman](Roman.md)
|
||||
* [Sf](Sf.md)
|
||||
* [Slug](Slug.md)
|
||||
* [Space](Space.md)
|
||||
* [StartsWith](StartsWith.md)
|
||||
* [String](String.md)
|
||||
* [SymbolicLink](SymbolicLink.md)
|
||||
* [Tld](Tld.md)
|
||||
* [True](True.md)
|
||||
* [Type](Type.md)
|
||||
* [Uploaded](Uploaded.md)
|
||||
* [Uppercase](Uppercase.md)
|
||||
* [Url](Url.md)
|
||||
* [Version](Version.md)
|
||||
* [Vowel](Vowel.md)
|
||||
* [When](When.md)
|
||||
* [Writable](Writable.md)
|
||||
* [Xdigit](Xdigit.md)
|
||||
* [Yes](Yes.md)
|
||||
* [Zend](Zend.md)
|
||||
|
||||
See also:
|
||||
|
||||
- [Contributing](../CONTRIBUTING.md)
|
||||
- [Feature Guide](README.md)
|
||||
- [Installation](INSTALL.md)
|
||||
- [License](../LICENSE.md)
|
9
docs/Version.md
Normal file
9
docs/Version.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Version
|
||||
|
||||
- `v::version()`
|
||||
|
||||
Validates version numbers using Semantic Versioning.
|
||||
|
||||
```php
|
||||
v::version()->validate('1.0.0');
|
||||
```
|
16
docs/Vowel.md
Normal file
16
docs/Vowel.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Vowel
|
||||
|
||||
- `v::vowel()`
|
||||
|
||||
Similar to `v::alnum()`. Validates strings that contains only vowels:
|
||||
|
||||
```php
|
||||
v::vowel()->validate('aei'); //true
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Alnum](Alnum.md)
|
||||
* [Digit](Digit.md)
|
||||
* [Alpha](Alpha.md)
|
||||
* [Consonant](Consonant.md)
|
23
docs/When.md
Normal file
23
docs/When.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
# When
|
||||
|
||||
- `v::when(v $if, v $then, v $else)`
|
||||
- `v::when(v $if, v $then)`
|
||||
|
||||
A ternary validator that accepts three parameters.
|
||||
|
||||
When the `$if` validates, returns validation for `$then`.
|
||||
When the `$if` doesn't validate, returns validation for `$else`, if defined.
|
||||
|
||||
```php
|
||||
v::when(v::int(), v::positive(), v::notEmpty())->validate($input);
|
||||
```
|
||||
|
||||
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.
|
||||
When `$else` is not defined use [AlwaysInvalid](AlwaysInvalid.md)
|
||||
|
||||
See also:
|
||||
|
||||
* [AllOf](AllOf.md)
|
||||
* [OneOf](OneOf.md)
|
||||
* [NoneOf](NoneOf.md)
|
9
docs/Writable.md
Normal file
9
docs/Writable.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Writable
|
||||
|
||||
- `v::writable()`
|
||||
|
||||
Validates if the given input is writable file.
|
||||
|
||||
```php
|
||||
v::writable()->validate('/path/of/a/writable/file'); //true
|
||||
```
|
21
docs/Xdigit.md
Normal file
21
docs/Xdigit.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Xdigit
|
||||
|
||||
- `v::xdigit()`
|
||||
|
||||
Accepts an hexadecimal number:
|
||||
|
||||
```php
|
||||
v::xdigit()->validate('abc123'); //true
|
||||
```
|
||||
|
||||
Notice, however, that it doesn't accept strings starting with 0x:
|
||||
|
||||
```php
|
||||
v::xdigit()->validate('0x1f'); //false
|
||||
```
|
||||
|
||||
See also:
|
||||
|
||||
* [Digit](Digit.md)
|
||||
* [Alnum](Alnum.md)
|
||||
* [HexRgbColor](HexRgbColor.md)
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue