Skip to content

Commit 9ef6519

Browse files
authored
Merge pull request #105 from fredchess/fredchess-add-cameroon-phone-valodator
[1.x] Add validation for `Cameroon` phone numbers
2 parents bf2deea + a6cb351 commit 9ef6519

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
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

docs/1.x/valid-phone-number.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,21 @@ return [
2828
<a name="support-countries-phone-number"></a>
2929
## Support Countries Phone Number
3030

31-
✅ IRAN <br>
32-
✅ ENGLAND <br>
33-
✅ NIGER <br>
34-
✅ SAUDI_ARABIA <br>
35-
✅ GERMANY <br>
36-
✅ GREECE <br>
37-
✅ SPAIN <br>
38-
✅ FRANCE <br>
39-
✅ INDIA <br>
40-
✅ INDONESIA <br>
41-
✅ ITALY <br>
42-
✅ JAPAN <br>
43-
✅ KOREAN <br>
44-
✅ RUSSIA <br>
45-
✅ SWEDEN <br>
46-
✅ TURKEY <br>
47-
✅ CHINA <br>
31+
- ✅ IRAN
32+
- ✅ ENGLAND
33+
- ✅ NIGER
34+
- ✅ SAUDI_ARABIA
35+
- ✅ GERMANY
36+
- ✅ GREECE
37+
- ✅ SPAIN
38+
- ✅ FRANCE
39+
- ✅ INDIA
40+
- ✅ INDONESIA
41+
- ✅ ITALY
42+
- ✅ JAPAN
43+
- ✅ KOREAN
44+
- ✅ RUSSIA
45+
- ✅ SWEDEN
46+
- ✅ TURKEY
47+
- ✅ CHINA
48+
- ✅ CAMEROON
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)