zendframework/zf2 — pull request #3884 by mwillbanks (2013-02-24 21:21:38+00:00)
Title: New I18n Validators: Country, Country Region, Iban and PhoneNumber

## Overview

### Country
The Country validator is based on ISO-3611 country codes. I needed this for actually integration into other systems that require an ISO-3611 country code. The key is the country code where as the value is the country name.
*Basic Usage:*
```php
$validator = new \Zend\I18n\Validator\Country();
$validator->isValid('US');

// input filter with context
$filter = new InputFilter();
$factory = new InputFactory();
$filter->add($factory->createInput(array(
'name' => 'country',
'required' => true,
'validators' => array(
'name' => 'Zend\I18n\Validator\Country',
),
)));
```

### Country Region
The Country Region validator is based on ISO36-11 region codes. It is a multi-dimensional hash that takes the country code as a key then the region code as the key and the region name as the value. The country code is primarily used so that you will only need to validate against a subset of items. A country is required.
*Basic Usage:*
```php
$validator = new \Zend\I18n\Validator\CountryRegion();
$validator->setCountry('US');
$validator->isValid('US-CA');

// input filter with context
$filter = new InputFilter();
$factory = new InputFactory();
// assumption here is that we have a country field coming through the context
$filter->add($factory->createInput(array(
'name' => 'country',
'required' => true,
'validators' => array(
'name' => 'Zend\I18n\Validator\Country',
),
)));
$filter->add($factory->createInput(array(
'name' => 'country-region',
'required' => true,
'validators' => array(
'name' => 'Zend\I18n\Validator\Country',
'options' => array(
'country' => 'country',
),
),
)));
```

### IBAN
The IBAN validator is based on the IBAN registry. It is a multi-dimensional hash that takes the country code as a key then the the bban and iban as subkeys that contain regular expressions. The country code is primarily used so that you will only need to validate against a subset of items. A country is required; however, it may be able to automatically be detected based off of the IBAN number itself; unless it is a regional iban number (aka france).
*Basic Usage:*
```php
$validator = new \Zend\I18n\Validator\Iban();
$validator->setCountry('AD'); // could be omitted since AD below is a country
$validator->isValid('AD1200012030200359100100');

// input filter with context; verify IBAN is part of the country
$filter = new InputFilter();
$factory = new InputFactory();
// assumption here is that we have a country field coming through the context
$filter->add($factory->createInput(array(
'name' => 'country',
'required' => true,
'validators' => array(
'name' => 'Zend\I18n\Validator\Country',
),
)));
$filter->add($factory->createInput(array(
'name' => 'iban',
'required' => true,
'validators' => array(
'name' => 'Zend\I18n\Validator\Iban',
'options' => array(
'country' => 'country',
),
),
)));
```

### Phone Number
The Phone Number validator is based on libPhoneNumber's XML file. It is a multi-dimensional hash that takes the country code as a key then several subkeys for possible types, national types and separated by types of numbers. The country is primarily used so that you will only need to validate against a subset of items. A country is required.
*Basic Usage:*
```php
$validator = new \Zend\I18n\Validator\PhoneNumber();
$validator->setCountry('US'); // could be omitted since AD below is a country
$validator->isValid('2015550123');

// input filter with context; verify IBAN is part of the country
$filter = new InputFilter();
$factory = new InputFactory();
// assumption here is that we have a country field coming through the context
$filter->add($factory->createInput(array(
'name' => 'country',
'required' => true,
'validators' => array(
'name' => 'Zend\I18n\Validator\Country',
),
)));
$filter->add($factory->createInput(array(
'name' => 'phoneNumber',
'required' => true,
'filters' => array(
'Digits',
),
'validators' => array(
'name' => 'Zend\I18n\Validator\PhoneNumber',
'options' => array(
'country' => 'country',
),
),
)));
```