mirror of
https://github.com/Respect/Validation.git
synced 2024-06-08 16:52:16 +02:00
ae369c4791
This commit will improve the Phone rule in the following ways: * Upgrade its validation engine; * Increase the number of tests; * Do not validate phone numbers from other regions. The last item is a possible bug with "libphonenumber-for-php", which I have already reported. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
58 lines
1.6 KiB
PHP
58 lines
1.6 KiB
PHP
--FILE--
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
use Respect\Validation\Validator as v;
|
|
|
|
run([
|
|
'Default' => [v::phone(), '123'],
|
|
'Country-specific' => [v::phone('BR'), '+1 650 253 00 00'],
|
|
'Negative' => [v::not(v::phone()), '+55 11 91111 1111'],
|
|
'Default with name' => [v::phone()->setName('Phone'), '123'],
|
|
'Country-specific with name' => [v::phone('US')->setName('Phone'), '123'],
|
|
]);
|
|
?>
|
|
--EXPECT--
|
|
Default
|
|
⎺⎺⎺⎺⎺⎺⎺
|
|
"123" must be a valid telephone number
|
|
- "123" must be a valid telephone number
|
|
[
|
|
'phone' => '"123" must be a valid telephone number',
|
|
]
|
|
|
|
Country-specific
|
|
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
|
|
"+1 650 253 00 00" must be a valid telephone number for country Brazil
|
|
- "+1 650 253 00 00" must be a valid telephone number for country Brazil
|
|
[
|
|
'phone' => '"+1 650 253 00 00" must be a valid telephone number for country Brazil',
|
|
]
|
|
|
|
Negative
|
|
⎺⎺⎺⎺⎺⎺⎺⎺
|
|
"+55 11 91111 1111" must not be a valid telephone number
|
|
- "+55 11 91111 1111" must not be a valid telephone number
|
|
[
|
|
'phone' => '"+55 11 91111 1111" must not be a valid telephone number',
|
|
]
|
|
|
|
Default with name
|
|
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
|
|
Phone must be a valid telephone number
|
|
- Phone must be a valid telephone number
|
|
[
|
|
'Phone' => 'Phone must be a valid telephone number',
|
|
]
|
|
|
|
Country-specific with name
|
|
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
|
|
Phone must be a valid telephone number for country United States
|
|
- Phone must be a valid telephone number for country United States
|
|
[
|
|
'Phone' => 'Phone must be a valid telephone number for country United States',
|
|
]
|