Closed Claudye closed 1 year ago
I wrote a class
Milwad\LaravelValidate\Utils\CountryPhoneCallback::class
that contains a list of methods to validate phone numbers according to the convention. Each method is named validateCODE()
and returns a boolean. This class allows writing any valid PHP code (not just a regex) to validate phone numbers.
In addition to that, the class contains a method called callPhoneValidator()
which allows to call the appropriate method to validate a phone number according to the provided country code.
This class takes as parameters in it constructor the phone number or a comma separated list of phone numbers, the ISO country code, and the attribute.
It is called in the ValidPhoneNumber
class if a $code
parameter has been passed to it, otherwise it executes the regular expression that was there
Ex:
public function phone_number_is_valid() {
$rules = [
'phone_number' => [new ValidPhoneNumber()],
'phone_bj' => [new ValidPhoneNumber(Country::BENIN)]
];
$data = ['phone_number' => '09366000000', 'phone_bj' => "+22997000000"];
$passes = $this->app['validator']->make($data, $rules)->passes();
$this->assertTrue($passes);
}
For example, how to validate Iran
phone number? where is it!
I don't know the phone number format of all countries. I did first if accepted I will add for other countries
Is important to add it soon!
I work on already
Users will now have the option to specify an optional parameter when instantiating the ValidPhoneNumber class, which will allow them to validate phone numbers for a specific country. If no parameter is specified, the default country will be used for validation.