Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Split Validate/Validate_IN

  • Loading branch information...
commit 9f22b5fade0f859a6a0a2a44a381bfa646257c7c 1 parent c9d83a9
@CloCkWeRX CloCkWeRX authored
Showing with 0 additions and 594 deletions.
  1. +0 −175 Validate/HU.php
  2. +0 −261 Validate/IN.php
  3. +0 −80 package_HU.xml
  4. +0 −78 package_IN.xml
View
175 Validate/HU.php
@@ -1,175 +0,0 @@
-<?php
-// +----------------------------------------------------------------------+
-// | Copyright (c) 2008 Tibor balogh, Zoltan Koteles |
-// +----------------------------------------------------------------------+
-// | Redistribution and use in source and binary forms, with or without |
-// | modification, are permitted provided that the following conditions |
-// | are met: |
-// | |
-// | Redistributions of source code must retain the above copyright |
-// | notice, this list of conditions and the following disclaimer. |
-// | |
-// | Redistributions in binary form must reproduce the above copyright |
-// | notice, this list of conditions and the following disclaimer in the |
-// | documentation and/or other materials provided with the distribution. |
-// | |
-// | Neither the name of the Tibor Balogh, Zoltan Koteles nor the names |
-// | of its contributors may be used to endorse or promote products |
-// | derived from this software without specific prior written permission.|
-// | |
-// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
-// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
-// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR|
-// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
-// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,|
-// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
-// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,|
-// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY|
-// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
-// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE|
-// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
-// +----------------------------------------------------------------------+
-// | Author: Tibor Balogh <btibor@dolphinet.hu> |
-// | Zoltan Koteles <koteleszoltan@dolphinet.hu> |
-// +----------------------------------------------------------------------+
-
-/**
- * Specific validation methods for data used in Hungary
- *
- * @category Validate
- * @package Validate_HU
- * @author Tibor Balogh <btibor@dolphinet.hu>
- * @author Zoltan Koteles <koteleszoltan@dolphinet.hu>
- * @copyright 2008 Tibor Balogh, Zoltan Koteles
- * @license http://www.opensource.org/licenses/bsd-license.php new BSD
- * @link http://www.dolphinet.hu
- */
-
-/**
- * Data validation class for Hungary
- *
- * This class provides methods to validate:
- * - Postal code (H-7090, 7090)
- * - Identity card (123456AA, AA123456)
- * - Tax number
- * - Bank account number
- * - SSN number (TAJ szam)
- *
- * @category Validate
- * @package Validate_HU
- * @author Tibor Balogh <btibor@dolphinet.hu>
- * @author Zoltan Koteles <koteleszoltan@dolphinet.hu>
- * @license http://www.opensource.org/licenses/bsd-license.php new BSD
- * @version Release: @package_version@
- * @link http://www.dolphinet.hu
- */
-class Validate_HU
-{
- /**
- * Validate a HU postcode
- *
- * @param string $postcode HU postcode to validate
- *
- * @return bool true if postcode is ok false otherwise
- */
- function postalCode($postcode)
- {
- return (bool)preg_match('/^(H-)?\d{4}$/', $postcode);
- }
-
- /**
- * Identity card validation check
- *
- * @param string $number Hungarian identity card
- *
- * @return bool true if identity card 'seems' correct
- */
- function identityCard($number)
- {
- return (bool)preg_match('/^[A-Z]{2}\d{6}$|^\d{6}[A-Z]{2}$/i', $number);
- }
-
- /**
- * Validates CDV of a number
- *
- * @param string $number number to check
- *
- * @access protected
- *
- * @return bool
- */
- function _checkCDV($number)
- {
- $cdv = intval(substr($number, -1));
- $digits = strlen($number)-1;
- $weights = array(9, 7, 3, 1);
- $sum = 0;
- for ($i = 0; $i < $digits; $i++) {
- $sum += $weights[$i % 4] * intval(substr($number, $i, 1));
- }
- return (((10 - ($sum % 10)) % 10) == $cdv);
- }
-
- /**
- * Tax number validation check
- *
- * @param mixed $number Hungarian taxnumber
- * @param mixed $dashes uses dashes in number or not
- *
- * @access public
- * @return void
- */
- function taxNumber($number, $dashes = false)
- {
- $dash = $dashes ? "-" : "";
- if (!preg_match("/^\d{8}".$dash."\d".$dash."\d{2}$/", $number)) {
- return false;
- }
- return Validate_HU::_checkCDV(substr($number, 0, 8));
- }
-
- /**
- * Bank account validation check
- *
- * @param string $number Hungarian bankaccount number
- * @param bool $dashes Number contains 1 or 2 dashes, default is false
- *
- * @return bool true if bankaccount number 'seems' correct
- */
-
- function bankAccountNumber($number, $dashes = false)
- {
- $dash = $dashes ? "-" : "";
- if (!preg_match("/^\d{8}".$dash."\d{8}(".$dash."\d{8})?$/", $number)) {
- return false;
- }
- $number = preg_replace("/-|0{8}$/", "", $number);
- $len = strlen($number);
-
- return
- Validate_HU::_checkCDV(substr($number, 0, 8)) &&
- (($len == 16 && Validate_HU::_checkCDV(substr($number, 8, 8))) ||
- ($len == 24 && Validate_HU::_checkCDV(substr($number, 8, 16))));
- }
-
- /**
- * Validate SSN (TAJ szam)
- *
- * @param string $ssn ssn number
- *
- * @access public
- * @return bool
- */
- function ssn($ssn)
- {
- if (!preg_match("/^\d{9}$/", $ssn)) return false;
-
- $weights = array(3, 7);
- $sum = 0;
- for ($i = 0; $i<8; $i++) {
- $sum += $weights[$i % 2] * intval(substr($ssn, $i, 1));
- }
- return substr($ssn, 8, 1) == ($sum % 10);
- }
-}
-?>
View
261 Validate/IN.php
@@ -1,261 +0,0 @@
-<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
-/**
- * Specific validation methods for data used in India
- *
- * PHP Versions 4 and 5
- *
- * This source file is subject to the New BSD license, That is bundled
- * with this package in the file LICENSE, and is available through
- * the world-wide-web at
- * http://www.opensource.org/licenses/bsd-license.php
- * If you did not receive a copy of the new BSDlicense and are unable
- * to obtain it through the world-wide-web, please send a note to
- * pajoye@php.net so we can mail you a copy immediately.
- *
- * @category Validate
- * @package Validate_IN
- * @author Anant Narayanan <anant@php.net>
- * @author Byron Adams <byron.adams54@gmail.com>
- * @copyright 1997-2005 Anant Narayanan
- * @copyright 2006 Byron Adams
- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @version CVS: $Id$
- * @link http://pear.php.net/package/Validate_IN
- */
-
-/**
- * Specific validation for data pertaining to the Republic of India.
- *
- * This class will validate Indian:
- * - Postal Codes (Zip Codes)
- * - State/U.T. Codes
- * - Telephone Numbers
- * - PAN/TAN Numbers
- * - Vehicle license plate Numbers
- *
- * @category Validate
- * @package Validate_IN
- * @author Anant Narayanan <anant@php.net>
- * @author Byron Adams <byron.adams54@gmail.com>
- * @copyright 1997-2005 Anant Narayanan
- * @copyright 2006 Byron Adams
- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @link http://pear.php.net/package/Validate_IN
- */
-
-class Validate_IN
-{
- /**
- * Validates an Indian Permanent Account Number (PAN) or
- * Tax deduction and collection Account Number (TAN).
- *
- * @param string $number the PAN or TAN to be validated.
- *
- * @access public
- * @return bool true on success false otherwise
- */
- function pan($number)
- {
- return preg_match('/^[A-Z]{3}[A-Z0-9]{7}$/', $number);
- }
-
- /**
- * Validates a state / union territory code and returns the full name of the
- * state / union territory code passed.
- *
- * @param string $stateCode 2-letter region code
- *
- * @access public
- * @see Validate_IN::region()
- *
- * @return bool true on success false otherwise
- */
- function stateCode($stateCode)
- {
- return Validate_IN::region($stateCode);
- }
-
- /**
- * Validates an Indian Vehicle's license plate number.
- *
- * @param string $number the license plate number to validate.
- *
- * @access public
- *
- * @return bool true on success false otherwise
- */
- function licensePlate($number)
- {
- $regex = "/^[A-Z]{2}(\s|\-)?[0-9]{1,2}(\s|\-)?(S|C|R|V)?"
- . "(\s|\-)?[A-Z]{0,2}(\s|\-)?\d{4}$/";
-
- if (Validate_IN::stateCode(substr($number, 0, 2))) {
- return preg_match($regex, $number);
- }
-
- return false;
- }
-
- /**
- * Validates an Indian Postal Code (ZIP code)
- *
- * @param string $postalCode The ZIP code to validate
- *
- * @access public
- *
- * @return bool true on success false otherwise
- */
- function postalCode($postalCode)
- {
- $postalCode = preg_replace("/[^\d]/", "", $postalCode);
-
- return (strlen($postalCode) == 6
- && $postalCode{0} != "0");
- }
-
- /**
- * Validates an Indian Permanent Account Number (PAN) or
- * Tax deduction and collection Account Number (TAN).
- *
- * @param string $ssn The PAN or TAN to be validated.
- *
- * @access public
- * @see Validate_AU::pan()
- *
- * @return bool true on success false otherwise
- *
- */
- function ssn($ssn)
- {
- return Validate_IN::pan($ssn);
- }
-
- /**
- * Validates a state / union territory code and returns the full name of the
- * state / union territory code passed.
- *
- * @param string $region 2-letter region code
- *
- * @access public
- * @return bool true on success false otherwise
- */
- function region($region)
- {
- static $states = array(
- "AN", "AP", "AR", "AS", "BR", "CH", "CT", "DN", "DD",
- "DL", "GA", "GJ", "HR", "HP", "JK", "JH", "KA", "KL",
- "LD", "MP", "MH", "MN", "ML", "MZ", "NL", "OR", "PY",
- "PB", "RJ", "SK", "TN", "TR", "UL", "UP", "WB");
-
- return in_array(strtoupper($region), $states);
- }
-
- /**
- * Returns the full name of a state / union territory given a valid state
- * code. If state code is invalid or NULL, an array of all states is
- * returned.
- *
- * @param string $code 2-letter region code
- *
- * @return bool true on success false otherwise
- * @return mixed Full name of state of code is valid, array of
- * all states if not.
- * @access public
- */
- function getStateName($code = null)
- {
- $code = strtoupper($code);
-
- static $states = array(
- "AN" => "Andaman and Nicobar Islands",
- "AP" => "Andhra Pradesh",
- "AR" => "Arunachal Pradesh",
- "AS" => "Assam",
- "BR" => "Bihar",
- "CH" => "Chandigarh",
- "CT" => "Chattisgarh",
- "DN" => "Dadra and Nagar Haveli",
- "DD" => "Daman and Diu",
- "DL" => "Delhi",
- "GA" => "Goa",
- "GJ" => "Gujarat",
- "HR" => "Harayana",
- "HP" => "Himachal Pradesh",
- "JK" => "Jammu and Kashmir",
- "JH" => "Jharkhand",
- "KA" => "Karnataka",
- "KL" => "Kerala",
- "LD" => "Lakshwadeep",
- "MP" => "Madhya Pradesh",
- "MH" => "Maharashtra",
- "MN" => "Manipur",
- "ML" => "Meghalaya",
- "MZ" => "Mizoram",
- "NL" => "Nagaland",
- "OR" => "Orissa",
- "PY" => "Pondicherry",
- "PB" => "Punjab",
- "RJ" => "Rajasthan",
- "SK" => "Sikkim",
- "TN" => "Tamil Nadu",
- "TR" => "Tripura",
- "UL" => "Uttaranchal",
- "UP" => "Uttar Pradesh",
- "WB" => "West Bengal");
-
- if (array_key_exists($code, $states)) {
- return $states[$code];
- } else {
- return $states;
- }
- }
-
- /**
- * Validate an Indian Phone number.
- *
- * Allows the following formats:
- *
- * (xxx) xxxxxxx
- * xxx xxxxxxx
- * +91 xxx xxxxxxx
- * 091xxxxxxxxxx
- *
- * where whitespaces, dashes and brackets may interchanged freely and 0/+ may
- * be added / skipped wherever possible.
- *
- * @param string $number Phone number to validate (mobile or landline)
- *
- * @access public
- * @static
- * @return bool True if number is valid, False otherwise
- */
- function phoneNumber($number)
- {
- // strip country code
- if (substr($number, 0, 3)=='091' or substr($number, 0, 3)=='+91') {
- $number = substr($number, 3, strlen($number)-3);
- }
- // no numbers in India begin with 91, so safely strip country code
- if (substr($number, 0, 2)=='91') {
- $number = substr($number, 2, strlen($number)-2);
- }
-
- // it's a mobile number
- if (preg_match('/^9(2|3|4|8|9)(\s)?(\-)?(\s)?[1-9]{1}[0-9]{7}$/', $number)) {
- return true;
- }
-
- // it's a landline, with or without area code
- $reg = "/^\(?(0[1-9]{2,5}|\d{2,5})?(\s)?(\s|\)|\-)?(\s)?(2|3|5)\d{6,7}$/";
- if (preg_match($reg, $number)) {
- return true;
- }
-
- return false;
- }
-
-
-
-}
-?>
View
80 package_HU.xml
@@ -1,80 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.5.4" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
- <name>Validate_HU</name>
- <channel>pear.php.net</channel>
- <summary>Validation class for Hungary</summary>
- <description>This class provides methods to validate:
-- Postal code (H-7090, 7090)
-- Identity card (123456AA, AA123456)
-- Tax number
-- Bank account number
-- SSN number (TAJ szam)</description>
- <lead>
- <name>Tibor Balogh</name>
- <user>tiberius</user>
- <email>btibor@dolphinet.hu</email>
- <active>yes</active>
- </lead>
- <lead>
- <name>Zoltan Koteles</name>
- <user>Dolphinet</user>
- <email>koteleszoltan@dolphinet.hu</email>
- <active>yes</active>
- </lead>
- <date>2008-03-11</date>
- <time>12:54:00</time>
- <version>
- <release>0.1.1</release>
- <api>0.1.1</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <license>New BSD</license>
- <notes>- bankAccountNumber validation method changed</notes>
- <contents>
- <dir name="/">
- <file md5sum="214258015a2fc8bcce553aa0008dc6bf" name="Validate/HU.php" role="php" />
- </dir>
- </contents>
- <dependencies>
- <required>
- <php>
- <min>4.4.0</min>
- </php>
- <pearinstaller>
- <min>1.4.0b1</min>
- </pearinstaller>
- </required>
- </dependencies>
- <phprelease />
- <changelog>
- <release>
- <version>
- <release>0.1.1</release>
- <api>0.1.1</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <date>2008-03-11</date>
- <license>New BSD</license>
- <notes>- bankAccountNumber validation method changed</notes>
- </release>
- <release>
- <version>
- <release>0.1.0</release>
- <api>0.1.0</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <date>2008-02-23</date>
- <license>New BSD</license>
- <notes />
- </release>
- </changelog>
-</package>
View
78 package_IN.xml
@@ -1,78 +0,0 @@
-<?xml version="1.0"?>
-<package version="2.0" xmlns="http://pear.php.net/dtd/package-2.0"
- xmlns:tasks="http://pear.php.net/dtd/tasks-1.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
-http://pear.php.net/dtd/tasks-1.0.xsd
-http://pear.php.net/dtd/package-2.0
-http://pear.php.net/dtd/package-2.0.xsd">
- <name>Validate_IN</name>
- <channel>pear.php.net</channel>
- <summary>Validation class for the Republic of India</summary>
- <description>Contains locale validation for Indian:
-* Permanent Account Number (PAN and TAN)
-* State and Union Territory codes
-* Telephone Numbers
-* Postal (Zip) Codes
-* Vehicle License Plate Numbers
- </description>
- <lead>
- <name>Anant Narayanan</name>
- <user>anant</user>
- <email>anant@php.net</email>
- <active>yes</active>
- </lead>
- <date>2006-03-18</date>
- <version>
- <release>0.1.1</release>
- <api>0.1.0</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL Version 2.1</license>
- <notes>
-QA release
-Bug #12043 Ran phpcs on IN.php: found 45 errors and 13 warnings
-Bug #12044 attempt to install package fails
-Bug #12066 no test present for region method
-</notes>
- <contents>
- <dir name="/">
- <dir name="Validate">
- <file name="IN.php" role="php" />
- </dir>
- </dir>
- </contents>
- <dependencies>
- <required>
- <php>
- <min>4.3.0</min>
- <max>6.0.0</max>
- </php>
- <pearinstaller>
- <min>1.4.1</min>
- </pearinstaller>
- </required>
- </dependencies>
-
- <phprelease />
-
- <changelog>
- <release>
- <version>
- <release>0.1.0</release>
- <api>0.1.0</api>
- </version>
- <stability>
- <release>alpha</release>
- <api>alpha</api>
- </stability>
- <date>2006-03-18</date>
- <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL Version 2.1</license>
- <notes>Initial release of package.</notes>
- </release>
- </changelog>
-
-</package>
Please sign in to comment.
Something went wrong with that request. Please try again.