From e470c31e484edd6ff0fa55c92e002175f419b902 Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Mon, 21 Sep 2015 13:27:26 -0300 Subject: [PATCH] Create "MySubdivisionCode" rule --- .../MySubdivisionCodeException.php | 31 +++++++++++++ .../SubdivisionCode/MySubdivisionCode.php | 45 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 library/Exceptions/SubdivisionCode/MySubdivisionCodeException.php create mode 100644 library/Rules/SubdivisionCode/MySubdivisionCode.php diff --git a/library/Exceptions/SubdivisionCode/MySubdivisionCodeException.php b/library/Exceptions/SubdivisionCode/MySubdivisionCodeException.php new file mode 100644 index 00000000..7fe991be --- /dev/null +++ b/library/Exceptions/SubdivisionCode/MySubdivisionCodeException.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 Malaysia subdivision code. + * + * ISO 3166-1 alpha-2: MY + */ +class MySubdivisionCodeException extends SubdivisionCodeException +{ + public static $defaultTemplates = array( + self::MODE_DEFAULT => array( + self::STANDARD => '{{name}} must be a subdivision code of Malaysia', + ), + self::MODE_NEGATIVE => array( + self::STANDARD => '{{name}} must not be a subdivision code of Malaysia', + ), + ); +} diff --git a/library/Rules/SubdivisionCode/MySubdivisionCode.php b/library/Rules/SubdivisionCode/MySubdivisionCode.php new file mode 100644 index 00000000..b5eb5da3 --- /dev/null +++ b/library/Rules/SubdivisionCode/MySubdivisionCode.php @@ -0,0 +1,45 @@ + + * + * 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 Malaysia subdivision code. + * + * ISO 3166-1 alpha-2: MY + * + * @link http://www.geonames.org/MY/administrative-division-malaysia.html + */ +class MySubdivisionCode extends AbstractSearcher +{ + public $haystack = array( + '01', // Johor + '02', // Kedah + '03', // Kelantan + '04', // Melaka + '05', // Negeri Sembilan + '06', // Pahang + '07', // Pinang + '08', // Perak + '09', // Perlis + '10', // Selangor + '11', // Terengganu + '12', // Sabah + '13', // Sarawak + '14', // Kuala Lumpur + '15', // Labuan + '16', // Putrajaya + ); + + public $compareIdentical = true; +}