Skip to content

Instantly share code, notes, and snippets.

@nissicreative
Last active January 3, 2017 21:20
Show Gist options
  • Save nissicreative/b871bea6d19e3c75d99c2455c3f93048 to your computer and use it in GitHub Desktop.
Save nissicreative/b871bea6d19e3c75d99c2455c3f93048 to your computer and use it in GitHub Desktop.
Laravel US Phone Validator
<?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