italiamultimedia / postal-code-validator
A postal code validator
dev-main
2023-03-22 14:55 UTC
Requires
- php: ^7.4||^8.1
Requires (Dev)
- pds/skeleton: ^1
- phan/phan: ^5
- php-parallel-lint/php-console-highlighter: ^1
- php-parallel-lint/php-parallel-lint: ^1
- phpcompatibility/php-compatibility: @dev
- phpmd/phpmd: ^2
- phpstan/phpstan: ^1
- phpstan/phpstan-strict-rules: ^1
- phpunit/phpunit: ^9
- slevomat/coding-standard: ^8
- squizlabs/php_codesniffer: ^3
- vimeo/psalm: ^4
Suggests
- phpdocumentor/phpdocumentor: phpDocumentor v3 (global installation)
This package is auto-updated.
Last update: 2024-04-22 17:13:27 UTC
README
Basic postal code validation (format only).
Regular expression patterns are taken from https://i18napis.appspot.com/address/data/{COUNTRY_CODE}
, however they are customized.
Usage example
composer require italiamultimedia/postal-code-validator
// Postal code validation $postalCodeValidator = new \ItaliaMultimedia\PostalCodeValidator\PostalCodeValidator(); $postalCodeFormatHelper = new \ItaliaMultimedia\PostalCodeValidator\PostalCodeFormatHelper(); try { // Check "to" if ($this->data('toPostalCode')) { if (!$postalCodeValidator->isValid($this->data('toCountryId'), $this->data('toPostalCode'))) { $this->errors['toPostalCode'][] = \sprintf( '%s %s', \sprintf(\__('This field is not valid: %s.'), $this->setting('meta/toPostalCode')), \sprintf( \__('Correct format: %s'), $postalCodeFormatHelper->getFormat($this->data('toCountryId')), ), ); } } } catch (\ItaliaMultimedia\PostalCodeValidator\PostalCodeValidatorException $e) { // Validation not available. Nothing to do. } // Postal code validation