Custom laravel validation rule for phone numbers

Rating: 
+1
-259
-1
Clone this Snippet
Just for validating correct phone numbers
<?php
class PhoneValidationRule extends \Illuminate\Validation\Validator {
  public function validatePhone($attribute, $value, $parameters){
    return preg_match("/^([0-9\s\-\+\(\)]*)$/", $value);
  }
}
// Register your custom validation rule
Validator::resolver(function($translator, $data, $rules, $messages) {
  return new PhoneValidationRule($translator, $data, $rules, $messages);
});
Category: 
Laravel