-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from milwad-dev/feat/add-dynamic-phone-validator
[1.x] Feat/add dynamic phone validator
- Loading branch information
Showing
26 changed files
with
321 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ composer.lock | |
.phpunit.result.cache | ||
phpunit.xml | ||
coverage | ||
.phpunit.cache |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,41 @@ | ||
<?php | ||
|
||
use Milwad\LaravelValidate\Rules\ValidBase64; | ||
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\DEPhoneValidator; | ||
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\ENPhoneValidator; | ||
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\ESPhoneValidator; | ||
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\FRPhoneValidator; | ||
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\GRPhoneValidator; | ||
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\IDPhoneValidator; | ||
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\INPhoneValidator; | ||
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\IRPhoneValidator; | ||
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\ITPhoneValidator; | ||
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\JAPhoneValidator; | ||
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\KOPhoneValidator; | ||
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\NEPhoneValidator; | ||
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\RUPhoneValidator; | ||
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\SAPhoneValidator; | ||
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\SEPhoneValidator; | ||
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\TRPhoneValidator; | ||
use Milwad\LaravelValidate\Utils\CountryPhoneValidator\ZHPhoneValidator; | ||
|
||
return [ | ||
'rules' => [ | ||
'base-64' => [ | ||
'name' => 'base64', | ||
'class' => ValidBase64::class, | ||
], | ||
'phone-country' => [ | ||
'DE' => DEPhoneValidator::class, | ||
'EN' => ENPhoneValidator::class, | ||
'ES' => ESPhoneValidator::class, | ||
'FR' => FRPhoneValidator::class, | ||
'GR' => GRPhoneValidator::class, | ||
'ID' => IDPhoneValidator::class, | ||
'IN' => INPhoneValidator::class, | ||
'IR' => IRPhoneValidator::class, | ||
'IT' => ITPhoneValidator::class, | ||
'JA' => JAPhoneValidator::class, | ||
'KO' => KOPhoneValidator::class, | ||
'NE' => NEPhoneValidator::class, | ||
'RU' => RUPhoneValidator::class, | ||
'SA' => SAPhoneValidator::class, | ||
'SE' => SEPhoneValidator::class, | ||
'TR' => TRPhoneValidator::class, | ||
'ZH' => ZHPhoneValidator::class, | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Milwad\LaravelValidate\Utils\CountryPhoneValidator; | ||
|
||
interface CountryPhoneValidator | ||
{ | ||
public function validate($value): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Milwad\LaravelValidate\Utils\CountryPhoneValidator; | ||
|
||
class DEPhoneValidator implements CountryPhoneValidator | ||
{ | ||
/** | ||
* Validate Iran phone numbers. | ||
*/ | ||
public function validate($value): bool | ||
{ | ||
return preg_match('/^((\+49)|(0))(1|15|16|17|19|30|31|32|33|34|40|41|42|43|44|49|151|152|153|155|156|157|159|160|162|163|180|181|182|183|184|185|186|187|188|170|171|172|173|174|175|176|177|178|179)\d{7,8}$/', $value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Milwad\LaravelValidate\Utils\CountryPhoneValidator; | ||
|
||
class ENPhoneValidator implements CountryPhoneValidator | ||
{ | ||
/** | ||
* Validate English phone numbers. | ||
*/ | ||
public function validate($value): bool | ||
{ | ||
return preg_match('/^(?:\+44|0)7\d{9}$/', $value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Milwad\LaravelValidate\Utils\CountryPhoneValidator; | ||
|
||
class ESPhoneValidator implements CountryPhoneValidator | ||
{ | ||
/** | ||
* Validate Spain phone numbers. | ||
*/ | ||
public function validate($value): bool | ||
{ | ||
return preg_match('/^(?:\+34|0034|34)?[6789]\d{8}$/', $value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Milwad\LaravelValidate\Utils\CountryPhoneValidator; | ||
|
||
class FRPhoneValidator implements CountryPhoneValidator | ||
{ | ||
/** | ||
* Validate France phone numbers. | ||
*/ | ||
public function validate($value): bool | ||
{ | ||
return preg_match('/^(?:\+33|0033|0)(?:[1-9](?:\d{2}){4}|[67]\d{8})$/', $value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Milwad\LaravelValidate\Utils\CountryPhoneValidator; | ||
|
||
class GRPhoneValidator implements CountryPhoneValidator | ||
{ | ||
/** | ||
* Validate Greece phone numbers. | ||
*/ | ||
public function validate($value): bool | ||
{ | ||
return preg_match('/^\+30[2-9]\d{2}\d{3}\d{4}$/', $value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Milwad\LaravelValidate\Utils\CountryPhoneValidator; | ||
|
||
class IDPhoneValidator implements CountryPhoneValidator | ||
{ | ||
/** | ||
* Validate Indonesia phone numbers. | ||
*/ | ||
public function validate($value): bool | ||
{ | ||
return preg_match('/^(?:\+62|0)(?:\d{2,3}\s?){1,2}\d{4,8}$/', $value); | ||
} | ||
} |
Oops, something went wrong.