|
1 | | -# Validate phone numbers with Laravel 5 |
2 | | -[](https://github.com/laravel-validation-rules/us-phone/releases) |
3 | | -[](LICENSE.md) |
4 | | -[](https://travis-ci.org/laravel-validation-rules/us-phone) |
5 | | -[](https://scrutinizer-ci.com/g/laravel-validation-rules/us-phone/?branch=master) |
6 | | -[](https://scrutinizer-ci.com/g/laravel-validation-rules/us-phone/?branch=master) |
7 | | -[](https://packagist.org/packages/laravel-validation-rules/us-phone) |
8 | | - |
9 | | -This package only checks phone number formatting and not actual number validity. |
| 1 | +# Phone |
| 2 | + |
| 3 | +Validates phone number format. |
| 4 | + |
| 5 | +<p > |
| 6 | + <a href="https://travis-ci.org/laravel-validation-rules/us-phone"> |
| 7 | + <img src="https://img.shields.io/travis/laravel-validation-rules/us-phone.svg?style=flat-square"> |
| 8 | + </a> |
| 9 | + <a href="https://scrutinizer-ci.com/g/laravel-validation-rules/us-phone/code-structure/master/code-coverage"> |
| 10 | + <img src="https://img.shields.io/scrutinizer/coverage/g/laravel-validation-rules/us-phone.svg?style=flat-square"> |
| 11 | + </a> |
| 12 | + <a href="https://scrutinizer-ci.com/g/laravel-validation-rules/us-phone"> |
| 13 | + <img src="https://img.shields.io/scrutinizer/g/laravel-validation-rules/us-phone.svg?style=flat-square"> |
| 14 | + </a> |
| 15 | + <a href="https://github.com/laravel-validation-rules/us-phone/blob/master/LICENSE"> |
| 16 | + <img src="https://img.shields.io/github/license/laravel-validation-rules/us-phone.svg?style=flat-square"> |
| 17 | + </a> |
| 18 | + <a href="https://twitter.com/clarkeash"> |
| 19 | + <img src="http://img.shields.io/badge/[email protected]?style=flat-square"> |
| 20 | + </a> |
| 21 | +</p> |
10 | 22 |
|
11 | 23 | ## Installation |
12 | 24 |
|
13 | | -Install via [composer](https://getcomposer.org/) - In the terminal: |
14 | 25 | ```bash |
15 | 26 | composer require laravel-validation-rules/us-phone |
16 | 27 | ``` |
17 | 28 |
|
18 | | -Now add the following to the `providers` array in your `config/app.php` |
19 | | -```php |
20 | | -LVR\Phone\ServiceProvider::class |
21 | | -``` |
22 | | - |
23 | 29 | ## Usage |
24 | 30 |
|
25 | 31 | ```php |
| 32 | +use LVR\Phone\Phone; |
| 33 | +use LVR\Phone\E164; |
| 34 | +use LVR\Phone\NANP; |
| 35 | +use LVR\Phone\Digits; |
| 36 | + |
26 | 37 | // Test any phone number |
27 | | -Validator::make(['test' => '15556667777'], ['test' => 'phone']); //true |
28 | | -Validator::make(['test' => '+15556667777'], ['test' => 'phone']); //true |
29 | | -Validator::make(['test' => '+1 (555) 666-7777'], ['test' => 'phone']); //true |
| 38 | +$request->validate(['test' => '15556667777'], new Phone); //true |
| 39 | +$request->validate(['test' => '+15556667777'], new Phone); //true |
| 40 | +$request->validate(['test' => '+1 (555) 666-7777'], new Phone); //true |
30 | 41 |
|
31 | 42 | // Test for E164 |
32 | | -Validator::make(['test' => '+15556667777'], ['test' => 'phone:E164']); //true |
| 43 | +$request->validate(['test' => '+15556667777'], ['test' => new E164]); //true |
33 | 44 |
|
34 | 45 | // Test for NANP (North American Numbering Plan) |
35 | | -Validator::make(['test' => '+1 (555) 666-7777'], ['test' => 'phone:NANP']); //true |
| 46 | +$request->validate(['test' => '+1 (555) 666-7777'], ['test' => new NANP); //true |
36 | 47 |
|
37 | 48 | // Test for digits only |
38 | | -Validator::make(['test' => '15556667777'], ['test' => 'phone:digits']); //true |
| 49 | +$request->validate(['test' => '15556667777'], ['test' => new Digits]); //true |
39 | 50 | ``` |
0 commit comments