Fix phone input (#201)
* Fix phone input * remove extra * fix factory * Fix phone input * Validate phone number rule * Prefill support for country only * Fix phone input error * fix tests --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
@@ -9,21 +9,16 @@ class ValidPhoneInputRule implements Rule
|
||||
{
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
if (!is_string($value) || !Str::startsWith($value, '+')) {
|
||||
return false;
|
||||
}
|
||||
if (!Str::startsWith($value, '+')) {
|
||||
return false;
|
||||
}
|
||||
$parts = explode(' ', $value);
|
||||
if (count($parts) < 2) {
|
||||
return false;
|
||||
}
|
||||
return strlen($parts[1]) >= 5;
|
||||
|
||||
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
|
||||
return $phoneUtil->isValidNumber($phoneUtil->parse($value));
|
||||
}
|
||||
|
||||
public function message()
|
||||
{
|
||||
return 'The :attribute must be a string that starts with a "+" character and must be at least 5 digits long.';
|
||||
return 'The :attribute is invalid.';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user