Files
opnform-host-nginx/app/Rules/ValidPhoneInputRule.php
formsdev d75975bdec 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>
2023-09-18 15:12:05 +02:00

24 lines
542 B
PHP

<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Str;
class ValidPhoneInputRule implements Rule
{
public function passes($attribute, $value)
{
if (!is_string($value) || !Str::startsWith($value, '+')) {
return false;
}
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
return $phoneUtil->isValidNumber($phoneUtil->parse($value));
}
public function message()
{
return 'The :attribute is invalid.';
}
}