Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix phone input #201

Merged
merged 8 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Http/Requests/AnswerFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private function getPropertyRules($property): array
}
return $this->getRulesForDate($property);
case 'phone_number':
return [new ValidPhoneInputRule];
return ['string', 'min:6', new ValidPhoneInputRule];
default:
return [];
}
Expand Down
15 changes: 5 additions & 10 deletions app/Rules/ValidPhoneInputRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.2",
"ext-json": "*",
"aws/aws-sdk-php": "^3.183",
"doctrine/dbal": "^3.4",
"fruitcake/laravel-cors": "^2.0",
"giggsey/libphonenumber-for-php": "^8.13",
"guzzlehttp/guzzle": "^7.0.1",
"jhumanj/laravel-model-stats": "^0.4.0",
"laravel/cashier": "^13.4",
Expand Down
Loading
Loading