Files
opnform-host-nginx/app/Rules/ValidPhoneInputRule.php
Sutirtha Bharati Das a53677d2ed ENH: Phone Input Component (#189)
* #170-ENH: Created custom dropdown phone input

* #170-ENH: Added phone_number rules

* #170-ENH: Added phone_number rules

* #170-ENH: Added separate Rule for phone number input, starting 0 phone number is ignored, added regex to ignore non digit phone input

* #170-ENH: Removed global registration of CountryFlag

* #170-ENH: Using VSelect component for country selection, added prop for dropdown styling

* #170-ENH: Updated phone number rule

* #170-ENH: Added margins to country selector

---------

Co-authored-by: Sutirtha <sdas@republicfinance.com>
Co-authored-by: Julien Nahum <julien@nahum.net>
2023-09-12 10:13:10 +02:00

29 lines
664 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)) {
return false;
}
if (!Str::startsWith($value, '+')) {
return false;
}
$parts = explode(' ', $value);
if (count($parts) < 2) {
return false;
}
return strlen($parts[1]) >= 5;
}
public function message()
{
return 'The :attribute must be a string that starts with a "+" character and must be at least 5 digits long.';
}
}