├── .styleci.yml ├── src ├── Facades │ └── SpanishValidator.php ├── InternalValidator.php ├── SpanishValidatorServiceProvider.php └── Validator.php ├── resources └── lang │ ├── en │ └── spanishValidator.php │ └── es │ └── spanishValidator.php ├── LICENSE.md ├── CHANGELOG.md ├── composer.json ├── CONTRIBUTING.md └── README.md /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | -------------------------------------------------------------------------------- /src/Facades/SpanishValidator.php: -------------------------------------------------------------------------------- 1 | 'This is not a valid spanish tax number.', 5 | 'spanish_personal_id' => 'This is not a valid personal id number.', 6 | 'nif' => 'This is not a valid NIF.', 7 | 'nie' => 'This is not a valid NIE.', 8 | 'cif' => 'This is not a valid CIF.', 9 | 'nss' => 'This is not a valid NSS.', 10 | 'iban' => 'This is not a valid IBAN.', 11 | 'spanish_postal_code' => 'The postal code is not valid.', 12 | 'spanish_phone' => 'Is not a valid spanih phone number.', 13 | ]; 14 | -------------------------------------------------------------------------------- /resources/lang/es/spanishValidator.php: -------------------------------------------------------------------------------- 1 | 'No es un CIF o NIF válido.', 5 | 'spanish_personal_id' => 'No es un número de identificación personal válido.', 6 | 'nif' => 'El NIF introducido no es válido.', 7 | 'nie' => 'El NIE introducido no es válido.', 8 | 'cif' => 'El CIF introducido no es válido.', 9 | 'nss' => 'El NSS introducido no es válido.', 10 | 'iban' => 'El IBAN introducido no es válido.', 11 | 'spanish_postal_code' => 'El código postal no es válido.', 12 | 'spanish_phone' => 'No es un número de teléfono válido.', 13 | ]; 14 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Daniel Muñoz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `laravel-spanish-identity-validator` will be documented in this file. 4 | 5 | ## 1.4.5 - 2025-08-27 6 | 7 | - Upgrade to support Laravel 12. (Thanks to Laravel Shift). 8 | 9 | 10 | ## 1.4.0 - 2024-08-24 11 | 12 | - Upgrade to Laravel 11. (Thanks to @rubenmdh) 13 | - Fix [issue #4](https://github.com/orumad/laravel-spanish-validator/issues/4). 14 | - Fix "lang" resource publishing. 15 | - Fix other lang files issues. 16 | - Added version number to composer.json. 17 | 18 | 19 | ## 1.3.0 - 2023-04-12 20 | 21 | - Upgrade to Laravel 10 and PHP 8.2. 22 | - Fix [issue #5](https://github.com/orumad/laravel-spanish-validator/issues/5). 23 | - Fix tests and added code coverage. 24 | 25 | 26 | ## 1.2.0 - 2022-02-24 27 | 28 | - Upgrade to PHP 8.0 and Laravel 9.0 29 | 30 | 31 | ## 1.1.2 - 2020-05-17 32 | 33 | - Update to Laravel 8.0 34 | - Fix StyleCI and build passes after upgrade to Laravel 8 35 | 36 | 37 | ## 1.1.1 - 2020-05-17 38 | 39 | - Fix a bug which required to publish the translation files always (even if you don't plane to edit them) 40 | 41 | 42 | ## 1.1.0 - 2020-05-17 43 | 44 | - Added a new rule: `spanish_personal_id` 45 | 46 | 47 | ## 1.0.3 - 2020-04-25 48 | 49 | - Upgrade to Laravel 7.0 50 | 51 | 52 | ## 1.0.2 - 2019-09-09 53 | 54 | - Upgrade to Laravel 6.0 55 | 56 | 57 | ## 1.0.1 - 2019-05-31 58 | 59 | - Fixed: test for invalid IBAN 60 | - Fixed: code style 61 | 62 | 63 | ## 1.0.0 - 2019-05-03 64 | 65 | - Initial release 66 | -------------------------------------------------------------------------------- /src/InternalValidator.php: -------------------------------------------------------------------------------- 1 | validator = new Validator(); 12 | } 13 | 14 | public function validateTaxNumber($attribute, $value, $parameters, $validator) 15 | { 16 | return $this->validator->isValidTaxNumber($value); 17 | } 18 | 19 | public function validatePersonalId($attribute, $value, $parameters, $validator) 20 | { 21 | return $this->validator->isValidPersonalId($value); 22 | } 23 | 24 | public function validateNif($attribute, $value, $parameters, $validator) 25 | { 26 | return $this->validator->isValidNif($value); 27 | } 28 | 29 | public function validateNie($attribute, $value, $parameters, $validator) 30 | { 31 | return $this->validator->isValidNie($value); 32 | } 33 | 34 | public function validateCif($attribute, $value, $parameters, $validator) 35 | { 36 | return $this->validator->isValidCif($value); 37 | } 38 | 39 | public function validateNss($attribute, $value, $parameters, $validator) 40 | { 41 | return $this->validator->isValidNss($value); 42 | } 43 | 44 | public function validateIban($attribute, $value, $parameters, $validator) 45 | { 46 | return $this->validator->isValidIban($value); 47 | } 48 | 49 | public function validatePostalCode($attribute, $value, $parameters, $validator) 50 | { 51 | return $this->validator->isValidPostalCode($value); 52 | } 53 | 54 | public function validatePhone($attribute, $value, $parameters, $validator) 55 | { 56 | return $this->validator->isValidPhone($value); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "danielmrdev/laravel-spanish-validator", 3 | "description": "Laravel validator for spanish stuff: NIF, NIE, CIF, NSS, IBAN, Postal Code, Phone numbers", 4 | "keywords": [ 5 | "orumad", 6 | "laravel validation rules", 7 | "laravel", 8 | "laravel package", 9 | "laravel validator" 10 | ], 11 | "homepage": "https://github.com/danielmrdev/laravel-spanish-validator", 12 | "version": "1.4.5", 13 | "license": "MIT", 14 | "authors": [ 15 | { 16 | "name": "Daniel MR", 17 | "email": "dev@danielmr.dev", 18 | "homepage": "https://danielmr.dev", 19 | "role": "Developer" 20 | } 21 | ], 22 | "require": { 23 | "php": "^8.2", 24 | "globalcitizen/php-iban": "^4.2.3", 25 | "illuminate/support": "^11.0|^12.0" 26 | }, 27 | "require-dev": { 28 | "orchestra/testbench": "^9.0|^10.0", 29 | "phpunit/phpunit": "^11.0", 30 | "scrutinizer/ocular": "master-dev" 31 | }, 32 | "autoload": { 33 | "psr-4": { 34 | "Orumad\\SpanishValidator\\": "src" 35 | } 36 | }, 37 | "autoload-dev": { 38 | "psr-4": { 39 | "Orumad\\SpanishValidator\\Tests\\": "tests" 40 | } 41 | }, 42 | "scripts": { 43 | "test": "vendor/bin/phpunit", 44 | "test-coverage": "vendor/bin/phpunit --coverage-html coverage" 45 | }, 46 | "config": { 47 | "sort-packages": true 48 | }, 49 | "extra": { 50 | "laravel": { 51 | "providers": [ 52 | "Orumad\\SpanishValidator\\SpanishValidatorServiceProvider" 53 | ], 54 | "aliases": { 55 | "SpanishValidator": "Orumad\\SpanishValidator\\Facades\\SpanishValidator" 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | Please read and understand the contribution guide before creating an issue or pull request. 6 | 7 | ## Etiquette 8 | 9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code 10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be 11 | extremely unfair for them to suffer abuse or anger for their hard work. 12 | 13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the 14 | world that developers are civilized and selfless people. 15 | 16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient 17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used. 18 | 19 | ## Viability 20 | 21 | When requesting or submitting new features, first consider whether it might be useful to others. Open 22 | source projects are used by many developers, who may have entirely different needs to your own. Think about 23 | whether or not your feature is likely to be used by other users of the project. 24 | 25 | ## Procedure 26 | 27 | Before filing an issue: 28 | 29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. 30 | - Check to make sure your feature suggestion isn't already present within the project. 31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress. 32 | - Check the pull requests tab to ensure that the feature isn't already in progress. 33 | 34 | Before submitting a pull request: 35 | 36 | - Check the codebase to ensure that your feature doesn't already exist. 37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix. 38 | 39 | ## Requirements 40 | 41 | If the project maintainer has any additional requirements, you will find them listed here. 42 | 43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). 44 | 45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 46 | 47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 48 | 49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option. 50 | 51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 52 | 53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 54 | 55 | **Happy coding**! 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel validator for spanish stuff: NIF, NIE, CIF, NSS, IBAN, Postal Code, Phone numbers 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/orumad/laravel-spanish-validator.svg?style=flat-square)](https://packagist.org/packages/orumad/laravel-spanish-validator) 4 | [![StyleCI](https://github.styleci.io/repos/184770182/shield?branch=main)](https://github.styleci.io/repos/184770182) 5 | [![Quality Score](https://img.shields.io/scrutinizer/g/orumad/laravel-spanish-validator.svg?style=flat-square)](https://scrutinizer-ci.com/g/orumad/laravel-spanish-validator) 6 | [![Total Downloads](https://img.shields.io/packagist/dt/orumad/laravel-spanish-validator.svg?style=flat-square)](https://packagist.org/packages/orumad/laravel-spanish-validator) 7 | 8 | This package is a set of diferent validation rules for spanish national id numbers like: 9 | 10 | - **NIF**: _"Número de Identificación Fiscal"_ (tax number for individuals). 11 | - **NIE**: _"Número de Idenfiticación para Extranjeros"_ (identity number for foreigners). 12 | - **CIF**: _"Código de Identificación Fiscal"_ (tax number for companies). 13 | - **NSS**: _"Número de la Seguridad Social"_ (national security number). 14 | 15 | Also the package include validators for: 16 | 17 | - **IBAN**: International Bank Account Number. 18 | - **Postal codes**: Spanish postal codes. 19 | - **Phone number**: Spanish phone numbers format. 20 | 21 | 22 | ## Instalation 23 | 24 | The package can be installed via composer: 25 | 26 | ```bash 27 | composer require orumad/laravel-spanish-validator 28 | ``` 29 | 30 | The package will automatically register itself. 31 | 32 | If you want to edit the validation messages, you should run the following command to publish the translation files into your `resources/lang` folder: 33 | 34 | ```bash 35 | php artisan vendor:publish --provider="Orumad\SpanishValidator\SpanishValidatorServiceProvider" 36 | ``` 37 | 38 | 39 | ## Available rules 40 | 41 | - [`nif`](#nif) 42 | - [`nie`](#nie) 43 | - [`cif`](#cif) 44 | - [`spanish_tax_number`](#spanish_tax_number) 45 | - [`spanish_personal_id`](#spanish_personal_id) 46 | - [`nss`](#nss) 47 | - [`iban`](#iban) 48 | - [`spanish_postal_code`](#spanish_postal_code) 49 | - [`spanish_phone`](#spanish_phone) 50 | 51 | 52 | ### `nif` 53 | 54 | Determine if the input is a valid _"Número de Identificación Fiscal"_ (tax number for individuals). 55 | 56 | 57 | ### `nie` 58 | 59 | Determine if the field under validation is a valid _"Número de Idenfiticación para Extranjeros"_ (identity number for foreigners). 60 | 61 | 62 | ### `cif` 63 | 64 | This rule will validate if the input field is a valid _"Código de Identificación Fiscal"_ (tax number for companies). 65 | 66 | 67 | ### `spanish_tax_number` 68 | 69 | This rule validates if the input is a valid spanish tax number: NIF or NIE or CIF. 70 | 71 | 72 | ### `spanish_personal_id` 73 | 74 | Will validate if the input is a valid personal id number in Spain (NIF or NIE). 75 | 76 | 77 | ### `nss` 78 | 79 | Determine if the field under validation is a valid "Número de la Seguridad Social"_ (national security number). 80 | 81 | 82 | ### `iban` 83 | 84 | Test if the input field is a valid IBAN bank account number. _(This uses the package `globalcitizen/php-iban` to check the validity of IBAN)_ 85 | 86 | 87 | ### `spanish_postal_code` 88 | 89 | Will check if the postal code is a valid spanish postal code. 90 | 91 | 92 | ### `spanish_phone` 93 | 94 | This tule validates if the input field content is a valid spanish phone number format. 95 | 96 | 97 | 98 | ### Testing 99 | 100 | ``` bash 101 | composer test 102 | ``` 103 | 104 | ### Changelog 105 | 106 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 107 | 108 | ## Contributing 109 | 110 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 111 | 112 | ### Security 113 | 114 | If you discover any security related issues, please email dev@danielmunoz.io instead of using the issue tracker. 115 | 116 | ## License 117 | 118 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 119 | -------------------------------------------------------------------------------- /src/SpanishValidatorServiceProvider.php: -------------------------------------------------------------------------------- 1 | getLangPath(); 15 | 16 | // Publish the lang files 17 | $this->publishes([ 18 | __DIR__.'/../resources/lang' => $publishPath, 19 | ], 'lang'); 20 | 21 | // Load the lang files 22 | $this->loadTranslationsFrom($publishPath, 'spanishValidator'); 23 | Lang::addNamespace('spanishValidator', __DIR__.'/../resources/lang'); 24 | 25 | // Add validators and messages 26 | $this->addValidators(); 27 | } 28 | 29 | private function getLangPath() 30 | { 31 | // Laravel >= 9 32 | if ($this->isLaravel9OrHigher()) { 33 | return lang_path('vendor/spanishvalidator'); 34 | } 35 | 36 | // Laravel < 9 37 | return resource_path('lang/vendor/spanishvalidator'); 38 | } 39 | 40 | private function isLaravel9OrHigher() 41 | { 42 | return version_compare(app()->version(), '9.0', '>='); 43 | } 44 | 45 | private function addValidators() 46 | { 47 | // Tax Number: NIF or NIE or CIF 48 | Validator::extend('spanish_tax_number', 'Orumad\\SpanishValidator\\InternalValidator@validateTaxNumber'); 49 | Validator::replacer('spanish_tax_number', function ($message, $attribute, $rule, $parameters) { 50 | return __('spanishValidator::spanishValidator.spanish_tax_number'); 51 | }); 52 | 53 | // Personal ID: NIF or NIE 54 | Validator::extend('spanish_personal_id', 'Orumad\\SpanishValidator\\InternalValidator@validatePersonalId'); 55 | Validator::replacer('spanish_personal_id', function ($message, $attribute, $rule, $parameters) { 56 | return __('spanishValidator::spanishValidator.spanish_personal_id'); 57 | }); 58 | 59 | // NIF 60 | Validator::extend('nif', 'Orumad\\SpanishValidator\\InternalValidator@validateNif'); 61 | Validator::replacer('nif', function ($message, $attribute, $rule, $parameters) { 62 | return __('spanishValidator::spanishValidator.nif'); 63 | }); 64 | 65 | // NIE 66 | Validator::extend('nie', 'Orumad\\SpanishValidator\\InternalValidator@validateNie'); 67 | Validator::replacer('nie', function ($message, $attribute, $rule, $parameters) { 68 | return __('spanishValidator::spanishValidator.nie'); 69 | }); 70 | 71 | // CIF 72 | Validator::extend('cif', 'Orumad\\SpanishValidator\\InternalValidator@validateCif'); 73 | Validator::replacer('cif', function ($message, $attribute, $rule, $parameters) { 74 | return __('spanishValidator::spanishValidator.cif'); 75 | }); 76 | 77 | // NSS 78 | Validator::extend('nss', 'Orumad\\SpanishValidator\\InternalValidator@validateNss'); 79 | Validator::replacer('nss', function ($message, $attribute, $rule, $parameters) { 80 | return __('spanishValidator::spanishValidator.nss'); 81 | }); 82 | 83 | // IBAN 84 | Validator::extend('iban', 'Orumad\\SpanishValidator\\InternalValidator@validateIban'); 85 | Validator::replacer('iban', function ($message, $attribute, $rule, $parameters) { 86 | return __('spanishValidator::spanishValidator.iban'); 87 | }); 88 | 89 | // Postal Code 90 | Validator::extend('spanish_postal_code', 'Orumad\\SpanishValidator\\InternalValidator@validatePostalCode'); 91 | Validator::replacer('spanish_postal_code', function ($message, $attribute, $rule, $parameters) { 92 | return __('spanishValidator::spanishValidator.spanish_postal_code'); 93 | }); 94 | 95 | // Phone 96 | Validator::extend('spanish_phone', 'Orumad\\SpanishValidator\\InternalValidator@validatePhone'); 97 | Validator::replacer('spanish_phone', function ($message, $attribute, $rule, $parameters) { 98 | return __('spanishValidator::spanishValidator.spanish_phone'); 99 | }); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/Validator.php: -------------------------------------------------------------------------------- 1 | isValidNif($value) or 13 | $this->isValidNie($value) or 14 | $this->isValidCif($value); 15 | } 16 | 17 | public function isValidPersonalId(?string $value): bool 18 | { 19 | return 20 | $this->isValidNif($value) or 21 | $this->isValidNie($value); 22 | } 23 | 24 | public function isValidNif(?string $value): bool 25 | { 26 | if ($value) { 27 | $regEx = '/^[0-9]{8}[A-Z]$/i'; 28 | 29 | $letters = 'TRWAGMYFPDXBNJZSQVHLCKE'; 30 | 31 | $value = strtoupper($value); 32 | 33 | if (preg_match($regEx, $value)) { 34 | return $letters[substr($value, 0, 8) % 23] == $value[8]; 35 | } 36 | } 37 | 38 | return false; 39 | } 40 | 41 | public function isValidNie(?string $value): bool 42 | { 43 | if ($value) { 44 | $regEx = '/^[KLMXYZ][0-9]{7}[A-Z]$/i'; 45 | $letters = 'TRWAGMYFPDXBNJZSQVHLCKE'; 46 | 47 | $value = strtoupper($value); 48 | 49 | if (preg_match($regEx, $value)) { 50 | $replaced = str_replace(['X', 'Y', 'Z'], [0, 1, 2], $value); 51 | 52 | return $letters[substr($replaced, 0, 8) % 23] == $value[8]; 53 | } 54 | } 55 | 56 | return false; 57 | } 58 | 59 | public function isValidCif(?string $value): bool 60 | { 61 | if ($value) { 62 | $regEx1 = '/^[ABEH][0-9]{8}$/i'; 63 | $regEx2 = '/^[KPQS][0-9]{7}[A-J]$/i'; 64 | $regEx3 = '/^[CDFGJLMNRUVW][0-9]{7}[0-9A-J]$/i'; 65 | 66 | $value = strtoupper($value); 67 | 68 | if (preg_match($regEx1, $value) || 69 | preg_match($regEx2, $value) || 70 | preg_match($regEx3, $value)) { 71 | $digit = $value[strlen($value) - 1]; 72 | $sum1 = 0; 73 | $sum2 = 0; 74 | 75 | for ($i = 1; $i < 8; $i++) { 76 | if ($i % 2 == 0) { 77 | $sum1 += intval($value[$i]); 78 | } else { 79 | $tot = (intval($value[$i]) * 2); 80 | $par = 0; 81 | 82 | for ($j = 0; $j < strlen($tot); $j++) { 83 | $par += substr($tot, $j, 1); 84 | } 85 | $sum2 += $par; 86 | } 87 | } 88 | 89 | $sum3 = intval($sum1 + $sum2).''; 90 | $sum4 = (10 - intval($sum3[strlen($sum3) - 1])) % 10; 91 | 92 | $letters = 'JABCDEFGHI'; 93 | 94 | if ($digit >= '0' && $digit <= '9') { 95 | return $digit == $sum4; 96 | } 97 | 98 | return strtoupper($digit) == $letters[$sum4]; 99 | } 100 | } 101 | 102 | return false; 103 | } 104 | 105 | public function isValidNSS(?string $value): bool 106 | { 107 | if ($value) { 108 | $regEx = '/^[0-9]{12}$/i'; 109 | 110 | if (preg_match($regEx, $value)) { 111 | $num1 = substr($value, 0, 2); 112 | $num2 = substr($value, 2, 8); 113 | $num3 = substr($value, 10, 2); 114 | $num4 = null; 115 | 116 | if ($num1 && $num2 && $num3) { 117 | if ($num2 < 10000000) { 118 | $num4 = $num2 + $num1 * 10000000; 119 | } else { 120 | $num4 = $num1.$num2; 121 | } 122 | $validacion = $num4 % 97; 123 | 124 | if ($validacion == $num3) { 125 | return true; 126 | } 127 | } 128 | } 129 | } 130 | 131 | return false; 132 | } 133 | 134 | public function isValidIban(?string $value): bool 135 | { 136 | if ($value) { 137 | $iban = new IBAN(); 138 | 139 | return $iban->Verify($value); 140 | } 141 | 142 | return false; 143 | } 144 | 145 | public function isValidPostalCode(?string $value): bool 146 | { 147 | if ($value) { 148 | $regEx = '/^(?:0[1-9]|[1-4]\d|5[0-2])\d{3}$/i'; 149 | 150 | return preg_match($regEx, $value) === 1; 151 | } 152 | 153 | return false; 154 | } 155 | 156 | public function isValidPhone(?string $value): bool 157 | { 158 | if ($value) { 159 | $regEx = '/^[9|8|6|7][0-9]{8}$/i'; 160 | 161 | return preg_match($regEx, $value) === 1; 162 | } 163 | 164 | return false; 165 | } 166 | } 167 | --------------------------------------------------------------------------------