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

ENH: Phone Input Component #189

Merged
merged 12 commits into from
Sep 12, 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
4 changes: 3 additions & 1 deletion app/Http/Requests/AnswerFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Validation\Rule;
use Illuminate\Http\Request;
use App\Rules\ValidHCaptcha;
use App\Rules\ValidPhoneInputRule;

class AnswerFormRequest extends FormRequest
{
Expand Down Expand Up @@ -150,7 +151,6 @@ private function getPropertyRules($property): array
{
switch ($property['type']) {
case 'text':
case 'phone_number':
case 'signature':
return ['string'];
case 'number':
Expand Down Expand Up @@ -189,6 +189,8 @@ private function getPropertyRules($property): array
return ['array', 'min:2'];
}
return $this->getRulesForDate($property);
case 'phone_number':
return [new ValidPhoneInputRule];
default:
return [];
}
Expand Down
29 changes: 29 additions & 0 deletions app/Rules/ValidPhoneInputRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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.';
}
}
Loading
Loading