Skip to content

Commit

Permalink
Merge pull request #105 from fredchess/fredchess-add-cameroon-phone-v…
Browse files Browse the repository at this point in the history
…alodator

[1.x] Add validation for `Cameroon` phone numbers
  • Loading branch information
milwad-dev authored Mar 3, 2025
2 parents bf2deea + a6cb351 commit 9ef6519
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
2 changes: 2 additions & 0 deletions config/laravel-validate.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Milwad\LaravelValidate\Utils\CountryPhoneValidator\CMPhoneValidator;
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\DEPhoneValidator;
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\ENPhoneValidator;
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\ESPhoneValidator;
Expand All @@ -26,6 +27,7 @@
* You can add custom country phone validator.
*/
'phone-country' => [
'CM' => CMPhoneValidator::class, // Cameroon
'DE' => DEPhoneValidator::class, // Germany
'EN' => ENPhoneValidator::class, // England
'ES' => ESPhoneValidator::class, // Spain
Expand Down
35 changes: 18 additions & 17 deletions docs/1.x/valid-phone-number.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@ return [
<a name="support-countries-phone-number"></a>
## Support Countries Phone Number

✅ IRAN <br>
✅ ENGLAND <br>
✅ NIGER <br>
✅ SAUDI_ARABIA <br>
✅ GERMANY <br>
✅ GREECE <br>
✅ SPAIN <br>
✅ FRANCE <br>
✅ INDIA <br>
✅ INDONESIA <br>
✅ ITALY <br>
✅ JAPAN <br>
✅ KOREAN <br>
✅ RUSSIA <br>
✅ SWEDEN <br>
✅ TURKEY <br>
✅ CHINA <br>
- ✅ IRAN
- ✅ ENGLAND
- ✅ NIGER
- ✅ SAUDI_ARABIA
- ✅ GERMANY
- ✅ GREECE
- ✅ SPAIN
- ✅ FRANCE
- ✅ INDIA
- ✅ INDONESIA
- ✅ ITALY
- ✅ JAPAN
- ✅ KOREAN
- ✅ RUSSIA
- ✅ SWEDEN
- ✅ TURKEY
- ✅ CHINA
- ✅ CAMEROON
11 changes: 11 additions & 0 deletions src/Utils/CountryPhoneValidator/CMPhoneValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Milwad\LaravelValidate\Utils\CountryPhoneValidator;

class CMPhoneValidator implements CountryPhoneValidator
{
public function validate($value): bool
{
return preg_match('/^(?:\+237|00237|237)?[26][256789][0-9]{7}$/', $value);
}
}
2 changes: 2 additions & 0 deletions tests/Rules/ValidPhoneNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function test_all_phone_number_is_valid_by_specific_code()
'phone_se' => [new ValidPhoneNumber(Country::SWEDEN)],
'phone_tr' => [new ValidPhoneNumber(Country::TURKEY)],
'phone_ch' => [new ValidPhoneNumber(Country::CHINA)],
'phone_cm' => [new ValidPhoneNumber(Country::CAMEROON)]
];
$data = [
'phone_ir' => '09125555555',
Expand All @@ -84,6 +85,7 @@ public function test_all_phone_number_is_valid_by_specific_code()
'phone_se' => '+46701234567',
'phone_tr' => '+905551234567',
'phone_ch' => '+8613812345678',
'phone_cm' => '+237691234564'
];
$passes = $this->app['validator']->make($data, $rules)->passes();

Expand Down

0 comments on commit 9ef6519

Please sign in to comment.