From a4e727826727fd36fda323ebd68a5e15c0dd6d44 Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Mon, 21 Sep 2015 13:26:56 -0300 Subject: [PATCH] Create "EsSubdivisionCode" rule --- .../EsSubdivisionCodeException.php | 31 ++++++ .../SubdivisionCode/EsSubdivisionCode.php | 98 +++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 library/Exceptions/SubdivisionCode/EsSubdivisionCodeException.php create mode 100644 library/Rules/SubdivisionCode/EsSubdivisionCode.php diff --git a/library/Exceptions/SubdivisionCode/EsSubdivisionCodeException.php b/library/Exceptions/SubdivisionCode/EsSubdivisionCodeException.php new file mode 100644 index 00000000..e5eb86af --- /dev/null +++ b/library/Exceptions/SubdivisionCode/EsSubdivisionCodeException.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the "LICENSE.md" + * file that was distributed with this source code. + */ + +namespace Respect\Validation\Exceptions\SubdivisionCode; + +use Respect\Validation\Exceptions\SubdivisionCodeException; + +/** + * Exception class for Spain subdivision code. + * + * ISO 3166-1 alpha-2: ES + */ +class EsSubdivisionCodeException extends SubdivisionCodeException +{ + public static $defaultTemplates = array( + self::MODE_DEFAULT => array( + self::STANDARD => '{{name}} must be a subdivision code of Spain', + ), + self::MODE_NEGATIVE => array( + self::STANDARD => '{{name}} must not be a subdivision code of Spain', + ), + ); +} diff --git a/library/Rules/SubdivisionCode/EsSubdivisionCode.php b/library/Rules/SubdivisionCode/EsSubdivisionCode.php new file mode 100644 index 00000000..f2b71f12 --- /dev/null +++ b/library/Rules/SubdivisionCode/EsSubdivisionCode.php @@ -0,0 +1,98 @@ + + * + * For the full copyright and license information, please view the "LICENSE.md" + * file that was distributed with this source code. + */ + +namespace Respect\Validation\Rules\SubdivisionCode; + +use Respect\Validation\Rules\AbstractSearcher; + +/** + * Validator for Spain subdivision code. + * + * ISO 3166-1 alpha-2: ES + * + * @link http://www.geonames.org/ES/administrative-division-spain.html + */ +class EsSubdivisionCode extends AbstractSearcher +{ + public $haystack = array( + 'AN', // Comunidad Autónoma de Andalucía + 'AR', // Comunidad Autónoma de Aragón + 'AS', // Comunidad Autónoma del Principado de Asturias + 'CB', // Comunidad Autónoma de Cantabria + 'CE', // Ceuta + 'CL', // Comunidad Autónoma de Castilla y León + 'CM', // Comunidad Autónoma de Castilla-La Mancha + 'CN', // Comunidad Autónoma de Canarias + 'CT', // Catalunya + 'EX', // Comunidad Autónoma de Extremadura + 'GA', // Comunidad Autónoma de Galicia + 'IB', // Comunidad Autónoma de las Islas Baleares + 'MC', // Comunidad Autónoma de la Región de Murcia + 'MD', // Comunidad de Madrid + 'ML', // Melilla + 'NC', // Comunidad Foral de Navarra + 'PV', // Euskal Autonomia Erkidegoa + 'RI', // Comunidad Autónoma de La Rioja + 'VC', // Comunidad Valenciana + 'A', // Alicante + 'AB', // Albacete + 'AL', // Almería + 'AV', // Ávila + 'B', // Barcelona + 'BA', // Badajoz + 'BI', // Vizcaya + 'BU', // Burgos + 'C', // A Coruña + 'CA', // Cádiz + 'CC', // Cáceres + 'CO', // Córdoba + 'CR', // Ciudad Real + 'CS', // Castellón + 'CU', // Cuenca + 'GC', // Las Palmas + 'GI', // Girona + 'GR', // Granada + 'GU', // Guadalajara + 'H', // Huelva + 'HU', // Huesca + 'J', // Jaén + 'L', // Lleida + 'LE', // León + 'LO', // La Rioja + 'LU', // Lugo + 'M', // Madrid + 'MA', // Málaga + 'MU', // Murcia + 'NA', // Navarra + 'O', // Asturias + 'OR', // Ourense + 'P', // Palencia + 'PM', // Baleares + 'PO', // Pontevedra + 'S', // Cantabria + 'SA', // Salamanca + 'SE', // Sevilla + 'SG', // Segovia + 'SO', // Soria + 'SS', // Guipúzcoa + 'T', // Tarragona + 'TE', // Teruel + 'TF', // Santa Cruz de Tenerife + 'TO', // Toledo + 'V', // Valencia + 'VA', // Valladolid + 'VI', // Álava + 'Z', // Zaragoza + 'ZA', // Zamora + ); + + public $compareIdentical = true; +}