Skip to content

Commit 1657b74

Browse files
committed
feat: add validation for cameroon phone numbers
1 parent bf2deea commit 1657b74

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

config/laravel-validate.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\CMPhoneValidator;
34
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\DEPhoneValidator;
45
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\ENPhoneValidator;
56
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\ESPhoneValidator;
@@ -26,6 +27,7 @@
2627
* You can add custom country phone validator.
2728
*/
2829
'phone-country' => [
30+
'CM' => CMPhoneValidator::class, // Cameroon
2931
'DE' => DEPhoneValidator::class, // Germany
3032
'EN' => ENPhoneValidator::class, // England
3133
'ES' => ESPhoneValidator::class, // Spain
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Milwad\LaravelValidate\Utils\CountryPhoneValidator;
4+
5+
class CMPhoneValidator implements CountryPhoneValidator
6+
{
7+
public function validate($value): bool
8+
{
9+
return preg_match('/^(?:\+237|00237|237)?[26][256789][0-9]{7}$/', $value);
10+
}
11+
}

tests/Rules/ValidPhoneNumberTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function test_all_phone_number_is_valid_by_specific_code()
6565
'phone_se' => [new ValidPhoneNumber(Country::SWEDEN)],
6666
'phone_tr' => [new ValidPhoneNumber(Country::TURKEY)],
6767
'phone_ch' => [new ValidPhoneNumber(Country::CHINA)],
68+
'phone_cm' => [new ValidPhoneNumber(Country::CAMEROON)]
6869
];
6970
$data = [
7071
'phone_ir' => '09125555555',
@@ -84,6 +85,7 @@ public function test_all_phone_number_is_valid_by_specific_code()
8485
'phone_se' => '+46701234567',
8586
'phone_tr' => '+905551234567',
8687
'phone_ch' => '+8613812345678',
88+
'phone_cm' => '+237691234564'
8789
];
8890
$passes = $this->app['validator']->make($data, $rules)->passes();
8991

0 commit comments

Comments
 (0)