Last active
January 3, 2017 21:20
-
-
Save nissicreative/b871bea6d19e3c75d99c2455c3f93048 to your computer and use it in GitHub Desktop.
Laravel US Phone Validator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Support\Facades\Validator; | |
// Add to AppServiceProvider's boot method | |
Validator::extend('us_phone', function ($attribute, $value, $parameters, $validator) { | |
return format_phone($value); | |
}); | |
Validator::replacer('us_phone', function ($message, $attribute, $rule, $parameters) { | |
return str_replace(':attribute', $attribute, 'The :attribute must be a valid US phone number.'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment