File tree Expand file tree Collapse file tree 5 files changed +66
-79
lines changed
Expand file tree Collapse file tree 5 files changed +66
-79
lines changed Original file line number Diff line number Diff line change 11<?php
22namespace LVR \Phone ;
33
4- use Illuminate \ Contracts \ Validation \ Rule ;
4+ use Closure ;
55
66class Digits extends Phone
77{
88 /**
9- * Determine if the validation rule passes.
10- *
11- * @param string $attribute
12- * @param mixed $value
13- *s
14- * @return bool
9+ * Validation error message
1510 */
16- public function passes ($ attribute , $ value )
17- {
18- return $ this ->isDigits ($ value );
19- }
11+ protected string $ message = ':attribute must be in digits only phone format ' ;
2012
2113 /**
22- * Get the validation error message .
14+ * Run the validation rule .
2315 *
24- * @return string
16+ * @param string $attribute
17+ * @param mixed $value
18+ * @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
19+ * @return void
2520 */
26- public function message ()
21+ public function validate ( string $ attribute , mixed $ value , Closure $ fail ): void
2722 {
28- return ':attribute must be in digits only phone format ' ;
23+ if (! $ this ->isDigits ($ value )) {
24+ $ fail ($ this ->message );
25+ }
2926 }
3027}
Original file line number Diff line number Diff line change 22
33namespace LVR \Phone ;
44
5+ use Closure ;
56
67class E123 extends Phone
78{
89 /**
9- * Determine if the validation rule passes.
10- *
11- * @param string $attribute
12- * @param mixed $value
13- *
14- * @return bool
10+ * Validation error message
1511 */
16- public function passes ($ attribute , $ value )
17- {
18- return $ this ->isE123 ($ value );
19- }
12+ protected string $ message = ':attribute must be in E.123 phone format ' ;
2013
2114 /**
22- * Get the validation error message .
15+ * Run the validation rule .
2316 *
24- * @return string
17+ * @param string $attribute
18+ * @param mixed $value
19+ * @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
20+ * @return void
2521 */
26- public function message ()
22+ public function validate ( string $ attribute , mixed $ value , Closure $ fail ): void
2723 {
28- return ':attribute must be in E.123 phone format ' ;
24+ if (! $ this ->isE123 ($ value )) {
25+ $ fail ($ this ->message );
26+ }
2927 }
30- }
28+ }
Original file line number Diff line number Diff line change 11<?php
22namespace LVR \Phone ;
33
4- use Illuminate \ Contracts \ Validation \ Rule ;
4+ use Closure ;
55
66class E164 extends Phone
77{
88 /**
9- * Determine if the validation rule passes.
10- *
11- * @param string $attribute
12- * @param mixed $value
13- *
14- * @return bool
9+ * Validation error message
1510 */
16- public function passes ($ attribute , $ value )
17- {
18- return $ this ->isE164 ($ value );
19- }
11+ protected string $ message = ':attribute must be in E.164 phone format ' ;
2012
2113 /**
22- * Get the validation error message .
14+ * Run the validation rule .
2315 *
24- * @return string
16+ * @param string $attribute
17+ * @param mixed $value
18+ * @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
19+ * @return void
2520 */
26- public function message ()
21+ public function validate ( string $ attribute , mixed $ value , Closure $ fail ): void
2722 {
28- return ':attribute must be in E.164 phone format ' ;
23+ if (! $ this ->isE164 ($ value )) {
24+ $ fail ($ this ->message );
25+ }
2926 }
30- }
27+ }
Original file line number Diff line number Diff line change 11<?php
22namespace LVR \Phone ;
33
4- use Illuminate \ Contracts \ Validation \ Rule ;
4+ use Closure ;
55
66class NANP extends Phone
77{
88 /**
9- * Determine if the validation rule passes.
10- *
11- * @param string $attribute
12- * @param mixed $value
13- *s
14- * @return bool
9+ * Validation error message
1510 */
16- public function passes ($ attribute , $ value )
17- {
18- return $ this ->isNANP ($ value );
19- }
11+ protected string $ message = ':attribute must be in the NANP phone format ' ;
2012
2113 /**
22- * Get the validation error message .
14+ * Run the validation rule .
2315 *
24- * @return string
16+ * @param string $attribute
17+ * @param mixed $value
18+ * @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
19+ * @return void
2520 */
26- public function message ()
21+ public function validate ( string $ attribute , mixed $ value , Closure $ fail ): void
2722 {
28- return ':attribute must be in the NANP phone format ' ;
23+ if (! $ this ->isNANP ($ value )) {
24+ $ fail ($ this ->message );
25+ }
2926 }
30- }
27+ }
Original file line number Diff line number Diff line change 11<?php
22namespace LVR \Phone ;
33
4- use Illuminate \Contracts \Validation \Rule ;
4+ use Closure ;
5+ use Illuminate \Contracts \Validation \ValidationRule ;
56
6- class Phone implements Rule
7+ class Phone implements ValidationRule
78{
89 /**
9- * Determine if the validation rule passes.
10- *
11- * @param string $attribute
12- * @param mixed $value
13- *
14- * @return bool
10+ * Validation error message
1511 */
16- public function passes ($ attribute , $ value )
17- {
18- return $ this ->isPhone ($ value );
19- }
12+ protected string $ message = 'Incorrect phone format for :attribute. ' ;
2013
2114 /**
22- * Get the validation error message .
15+ * Run the validation rule .
2316 *
24- * @return string
17+ * @param string $attribute
18+ * @param mixed $value
19+ * @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
20+ * @return void
2521 */
26- public function message ()
22+ public function validate ( string $ attribute , mixed $ value , Closure $ fail ): void
2723 {
28- return 'Incorrect phone format for :attribute. ' ;
24+ if (! $ this ->isPhone ($ value )) {
25+ $ fail ($ this ->message );
26+ }
2927 }
3028
3129 /**
@@ -90,4 +88,4 @@ protected function isNANP($value)
9088 $ conditions [] = preg_match ("/^(?:\+1|1)?\s?-?\(?\d{3}\)?(\s|-)?\d{3}-\d{4}$/i " , $ value ) > 0 ;
9189 return (bool ) array_product ($ conditions );
9290 }
93- }
91+ }
You can’t perform that action at this time.
0 commit comments