Validate_IR
[ class tree: Validate_IR ] [ index: Validate_IR ] [ all elements ]

Source for file IR.php

Documentation is available at IR.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3.  
  4. /**
  5.  * Specific validation methods for data used in the Iran.
  6.  *
  7.  * PHP version 5
  8.  *
  9.  * This source file is subject to the New BSD license,
  10.  * That is bundled with this package in the file LICENSE,
  11.  * and is available through the world-wide-web at http://www.opensource.org/licenses/bsd-license.php
  12.  * If you did not receive a copy of the new BSDlicense and are unable to obtain it through the world-wide-web,
  13.  * please send a note to pajoye@php.net so we can mail you a copy immediately.
  14.  * 
  15.  * @category  Validate
  16.  * @package   Validate_IR
  17.  * @author    Arash Hemmat <arash.hemmat@gmail.com>
  18.  * @copyright 2011 Arash Hemmat
  19.  * @license   http://www.opensource.org/licenses/bsd-license.php  new BSD
  20.  * @link      http://pear.php.net/package/Validate_IR
  21.  */
  22. {
  23.     /**
  24.      * Check for Persian/Farsi characters and number an zero width non-joiner space.
  25.      * Also accpets latin numbers preventing potential problem until PHP becomes fully unicode compatible.
  26.      *
  27.      * @param string $check The value to check.
  28.      *
  29.      * @return boolean 
  30.      * @access public
  31.      */
  32.     function alphaNumeric($check
  33.     {
  34.         $pattern '/[^\x{0600}-\x{06FF}\x{FB50}-\x{FDFD}\x{FE70}-\x{FEFF}\x{0750}-\x{077F}0-9\s\x{200C}]+/u';
  35.         return !preg_match($pattern$check);
  36.     }
  37.  
  38.     /**
  39.      * Checks for Persian/Farsi digits only and won't accept Arabic and Latin digits.
  40.      *
  41.      * @param string $check The value to check.
  42.      *
  43.      * @return boolean 
  44.      * @access public
  45.      */
  46.     function numeric($check
  47.     {
  48.         $pattern '/[^\x{06F0}-\x{06F9}\x]+/u';
  49.         return !preg_match($pattern$check);
  50.     }
  51.  
  52.     /**
  53.      * Validation of Iran credit card numbers.
  54.      *
  55.      * @param string $check The value to check.
  56.      *
  57.      * @return boolean 
  58.      * @access public
  59.      */
  60.     function creditCard($check
  61.     {
  62.         $pattern '/^[0-9]{4}-?[0-9]{4}-?[0-9]{4}-?[0-9]{4}$/';
  63.         return preg_match($pattern$check);
  64.     }
  65.  
  66.     /**
  67.      * Checks phone numbers for Iran
  68.      *
  69.      * @param string $check The value to check.
  70.      *
  71.      * @return boolean 
  72.      * @access public
  73.      */
  74.     function phoneNumber($check
  75.     {
  76.         $pattern '/^[- .\(\)]?((98)|(\+98)|(0098)|0){1}[- .\(\)]{0,3}[1-9]{1}[0-9]{1,}[- .\(\)]*[0-9]{3,8}[- .\(\)]?$/';
  77.         return preg_match($pattern$check);
  78.     }
  79.  
  80.     /**
  81.      * Checks mobile numbers for Iran
  82.      *
  83.      * @param string $check The value to check.
  84.      *
  85.      * @return boolean 
  86.      * @access public 0 9 124061351
  87.      */
  88.     function mobileNumber($check
  89.     {
  90.         $pattern '/^[- .\(\)]?((98)|(\+98)|(0098)|0){1}[- .\(\)]{0,3}((91)|(93)){1}[0-9]{8}$/';
  91.         return preg_match($pattern$check);
  92.     }
  93.  
  94.     /**
  95.      * Checks postal codes for Iran
  96.      *
  97.      * @param string $check The value to check.
  98.      *
  99.      * @return boolean 
  100.      * @access public
  101.      */
  102.     function postalCode($check
  103.     {
  104.         $pattern '/^\d{10}$/';
  105.         return preg_match($pattern$check);
  106.     }
  107.  
  108.     /**
  109.      * Checks social security numbers for Iran called "kode melli".
  110.      * kode melli's last digit from left is the check digit, here is the algorithm:
  111.      * A= last digit from left
  112.      * B= (first digit*10) + (2th digit*9) + ... (9th digit *2)
  113.      * C= B – (B/11)*11
  114.      * if C==0 and A==0 OK
  115.      * if C==1 and A==1 OK
  116.      * if C>1 and A==(C-11) OK
  117.      *
  118.      * @param string $check The value to check.
  119.      *
  120.      * @return boolean 
  121.      * @access public
  122.      */
  123.     function ssn($check
  124.     {
  125.         $pattern '/^\d{10}$/';
  126.         if (!preg_match($pattern$check)) {
  127.             return false;
  128.         }
  129.  
  130.         $sum = 0;
  131.         $equivalent = 0;
  132.  
  133.         for ($i = 0; $i < 9; $i++{
  134.             $sum += $check{$i(10 - $i);
  135.             if ($check{1== $check{$i}{
  136.                 $equivalent++;
  137.             }
  138.         }
  139.  
  140.         if ($equivalent == 9{
  141.             return false;
  142.         }
  143.  
  144.         $remaining $sum % 11;
  145.  
  146.         if ($remaining <= 1{
  147.             return (bool)($remaining == $check{9});
  148.         }
  149.  
  150.         return (bool)((11 - $remaining== $check{9});
  151.     }
  152. }

Documentation generated on Mon, 11 Mar 2019 15:43:21 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.