Phone input prefill country issue fixed (#213)

* fix prefill phone issue

* js phone parse fixes

* revert last change

* fix phone UI

* Code optimize

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
formsdev
2023-10-03 21:20:46 +05:30
committed by GitHub
parent 54f92f844f
commit f7ecd6f233
7 changed files with 310 additions and 38 deletions

View File

@@ -12,10 +12,13 @@ class ValidPhoneInputRule implements Rule
public function passes($attribute, $value)
{
if (!is_string($value) || !Str::startsWith($value, '+')) {
if (!is_string($value) || !$value) {
return false;
}
try {
if(ctype_alpha(substr($value, 0, 2))){ // First 2 will be country code
$value = substr($value, 2);
}
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$phone = $phoneUtil->parse($value);
$this->reason = $phoneUtil->isPossibleNumberWithReason($phone);