Skip to content

Commit dfedad9

Browse files
committed
phone number rule, TG,NE,GW,TD,CM,BF,AO
1 parent b37935b commit dfedad9

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/Utils/CountryPhoneCallback.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,35 @@ class CountryPhoneCallback
1414
public function __construct(protected $value, protected string $code, $attribute = null)
1515
{
1616
}
17+
protected function validateTG()
18+
{
19+
return preg_match('/^(\+228|00228|228)?\d{8}$/', $this->value);
20+
}
21+
protected function validateNE()
22+
{
23+
return preg_match('/^(\+227|00227|227)?\d{8}$/', $this->value);
24+
}
25+
26+
protected function validateGW()
27+
{
28+
return preg_match('/^(\+245|00245|245)?\d{7,8}$/', $this->value);
29+
}
30+
protected function validateTD()
31+
{
32+
return preg_match('/^(\+235|00235|235)?\d{8}$/', $this->value);
33+
}
34+
protected function validateCM()
35+
{
36+
return preg_match('/^(\+237|00237|237)?\d{8}$/', $this->value);
37+
}
38+
protected function validateBF()
39+
{
40+
return preg_match('/^(\+226|00226|226)?\d{8}$/', $this->value);
41+
}
42+
protected function validateAO(): bool
43+
{
44+
return preg_match('/^(\+244|00244|244)?[9,2][1-9]\d{7}$/', $this->value);
45+
}
1746

1847
protected function validateBJ(): bool
1948
{
@@ -36,7 +65,7 @@ public function callPhoneValidator(): array
3665
$codes = array_map('strtoupper', $codes);
3766

3867
foreach ($codes as $code) {
39-
$methodName = 'validate'.$code;
68+
$methodName = 'validate' . $code;
4069

4170
if (method_exists($this, $methodName)) {
4271
$results[$code] = $this->{$methodName}();

tests/Rules/ValidPhoneNumberTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public function phone_number_is_valid()
2727
{
2828
$rules = [
2929
'phone_number' => [new ValidPhoneNumber()],
30-
'phone_bj' => [new ValidPhoneNumber(Country::BENIN)],
30+
'phone_ne' => [new ValidPhoneNumber(Country::NIGER)],
3131
];
32-
$data = ['phone_number' => '09366000000', 'phone_bj' => '+22997000000'];
32+
$data = ['phone_number' => '09366000000', 'phone_ne' => '+22799123456'];
3333
$passes = $this->app['validator']->make($data, $rules)->passes();
3434

3535
$this->assertTrue($passes);

0 commit comments

Comments
 (0)