PHP code example of italiamultimedia / postal-code-validator

1. Go to this page and download the library: Download italiamultimedia/postal-code-validator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

italiamultimedia / postal-code-validator example snippets


// 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