Source for file Phone.class.php

Documentation is available at Phone.class.php

  1. <?php
  2. /**
  3.  * Gumbo Library Framework
  4.  *
  5.  * LICENSE
  6.  * This library is being released under the terms of the New BSD License.  A
  7.  * copy of the license is packaged with the software (LICENSE.txt).  If no
  8.  * copy is found, a copy of the license template can be found at:
  9.  * http://www.opensource.org/licenses/bsd-license.php
  10.  * 
  11.  * @category Gumbo
  12.  * @package Valid
  13.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  14.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  15.  * @author Michael Luster <mluster79@yahoo.com>
  16.  * @link http://sourceforge.net/projects/phpgumbo
  17.  * @version 0.0.1
  18.  */
  19.  
  20. /**
  21.  * Phone Number Validation Class
  22.  *
  23.  * @category Gumbo
  24.  * @package Valid
  25.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  26.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  27.  * @author Michael Luster <mluster79@yahoo.com>
  28.  * @link http://sourceforge.net/projects/phpgumbo
  29.  * @desc Phone Number Validation Class
  30.  * @version 0.0.1
  31.  */
  32.  
  33. gumbo_load ("Valid");
  34.  
  35. class Gumbo_Valid_Phone extends Gumbo_Valid {
  36.     
  37.     /**
  38.      * Constructor
  39.      * @param bool $throw throw Exceptions
  40.      * @param int $level Error Level thrown
  41.      */
  42.     public function __construct ($throw=false$level=null{
  43.         parent::__construct ($throw$level);
  44.     }
  45.     
  46.     
  47.     
  48.     /**
  49.      * Returns if the value is a Phone Number
  50.      * @param string $val 
  51.      * @return bool 
  52.      * @todo implement this method
  53.      */
  54.     public function isPhone ($val{
  55.         return false;
  56.     }
  57.     
  58.     /**
  59.      * Returns if the value is a valid US Phone Number
  60.      * @param string $val 
  61.      * @return bool 
  62.      * @throws Gumbo_Exception
  63.      */
  64.     public function isPhoneUS ($val{
  65.         $passed false;
  66.         
  67.         $this->turnOn ();
  68.         try {
  69.             // verify precondition
  70.             $this->precondition ($val"str""num");
  71.             $val preg_replace ("[^0-9]"""$val);
  72.             $this->isMatch ($val"^([0-9]{3})([0-9]{3})([0-9]{4})$");
  73.             $passed true;
  74.         catch (Exception $e{
  75.             $e null;
  76.         }
  77.         $this->turnOff ();
  78.                 
  79.         if (!$passed && $this->isThrowing ()) {
  80.             throw new Gumbo_Exception ("Validation Failed: US Phone Number"$this->getLevel ());
  81.         }
  82.         return $passed;
  83.     }
  84.     
  85. }
  86.  
  87. ?>