From e71699d8bc42d44c58fa9c966bcdd2ce97b187f6 Mon Sep 17 00:00:00 2001 From: Henrique Moody Date: Mon, 21 Sep 2015 13:27:06 -0300 Subject: [PATCH] Create "InSubdivisionCode" rule --- .../InSubdivisionCodeException.php | 31 +++++++++ .../SubdivisionCode/InSubdivisionCode.php | 64 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 library/Exceptions/SubdivisionCode/InSubdivisionCodeException.php create mode 100644 library/Rules/SubdivisionCode/InSubdivisionCode.php diff --git a/library/Exceptions/SubdivisionCode/InSubdivisionCodeException.php b/library/Exceptions/SubdivisionCode/InSubdivisionCodeException.php new file mode 100644 index 00000000..a1d29579 --- /dev/null +++ b/library/Exceptions/SubdivisionCode/InSubdivisionCodeException.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 India subdivision code. + * + * ISO 3166-1 alpha-2: IN + */ +class InSubdivisionCodeException extends SubdivisionCodeException +{ + public static $defaultTemplates = array( + self::MODE_DEFAULT => array( + self::STANDARD => '{{name}} must be a subdivision code of India', + ), + self::MODE_NEGATIVE => array( + self::STANDARD => '{{name}} must not be a subdivision code of India', + ), + ); +} diff --git a/library/Rules/SubdivisionCode/InSubdivisionCode.php b/library/Rules/SubdivisionCode/InSubdivisionCode.php new file mode 100644 index 00000000..7600bd1b --- /dev/null +++ b/library/Rules/SubdivisionCode/InSubdivisionCode.php @@ -0,0 +1,64 @@ + + * + * 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 India subdivision code. + * + * ISO 3166-1 alpha-2: IN + * + * @link http://www.geonames.org/IN/administrative-division-india.html + */ +class InSubdivisionCode extends AbstractSearcher +{ + public $haystack = array( + 'AN', // Andaman and Nicobar Islands + 'AP', // Andhra Pradesh + 'AR', // Arunachal Pradesh + 'AS', // Assam + 'BR', // Bihar + 'CH', // Chandigarh + 'CT', // Chhattisgarh + 'DD', // Daman and Diu + 'DL', // Delhi + 'DN', // Dadra and Nagar Haveli + 'GA', // Goa + 'GJ', // Gujarat + 'HP', // Himachal Pradesh + 'HR', // Haryana + 'JH', // Jharkhand + 'JK', // Jammu and Kashmir + 'KA', // Karnataka + 'KL', // Kerala + 'LD', // Lakshadweep + 'MH', // Maharashtra + 'ML', // Meghalaya + 'MN', // Manipur + 'MP', // Madhya Pradesh + 'MZ', // Mizoram + 'NL', // Nagaland + 'OR', // Orissa + 'PB', // Punjab + 'PY', // Pondicherry + 'RJ', // Rajasthan + 'SK', // Sikkim + 'TN', // Tamil Nadu + 'TR', // Tripura + 'UL', // Uttaranchal + 'UP', // Uttar Pradesh + 'WB', // West Bengal + ); + + public $compareIdentical = true; +}