Source for file Web.class.php

Documentation is available at Web.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.  * Web 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 Web Validation Class
  30.  * @version 0.0.1
  31.  */
  32.  
  33. gumbo_load ("Valid");
  34.  
  35. class Gumbo_Valid_Web 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 an Email Address
  50.      * @param string $val 
  51.      * @return bool 
  52.      * @throws Gumbo_Exception
  53.      */
  54.     public function isEmail ($val{
  55.         $passed false;
  56.         
  57.         $this->turnOn ();
  58.         try {
  59.             $this->precondition ($val"str");
  60.             $this->isMatch ($val"^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$");
  61.             $passed true;
  62.         catch (Exception $e{
  63.             $e null;
  64.         }
  65.         $this->turnOff ();
  66.         
  67.         if (!$passed && $this->isThrowing ()) {
  68.             throw new Gumbo_Exception ("Validation Failed: Email"$this->getLevel ());
  69.         }
  70.         return $passed;
  71.     }
  72.     
  73.     /**
  74.      * Returns if the value is a URL
  75.      * @param string $val 
  76.      * @return bool 
  77.      * @throws Gumbo_Exception
  78.      */
  79.     public function isUrl ($val{
  80.         $passed false;
  81.         
  82.         $this->turnOn ();
  83.         try {
  84.             $this->precondition ($val"str");
  85.             $this->isMatch ($val"^((ht|f)tp://)?(([a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3}))|(([0-9]{1,3}.){3}([0-9]{1,3})))$");
  86.             $passed true;
  87.         catch (Exception $e{
  88.             $e null;
  89.         }
  90.         $this->turnOff ();
  91.         
  92.         if (!$passed && $this->isThrowing ()) {
  93.             throw new Gumbo_Exception ("Validation Failed: URL"$this->getLevel ());
  94.         }
  95.         return $passed;
  96.     }
  97.     
  98.     /**
  99.      * Returns if the value is an IP Address
  100.      * @param string $val 
  101.      * @return bool 
  102.      * @throws Gumbo_Exception
  103.      */
  104.     public function isIpAddress ($val{
  105.         $passed false;
  106.         
  107.         $this->turnOn ();
  108.         try {
  109.             $this->precondition ($val"str");
  110.             $this->isMatch ($val"([0-255]{1,3}).([0-255]{1,3}).([0-255]{1,3}).([0-255]{1,3})");
  111.             $passed true;
  112.         catch (Exception $e{
  113.             $e null;
  114.         }
  115.         $this->turnOff ();
  116.         
  117.         if (!$passed && $this->isThrowing ()) {
  118.             throw new Gumbo_Exception ("Validation Failed: IP Address"$this->getLevel ());
  119.         }
  120.         return $passed;
  121.     }
  122.     
  123. }
  124.  
  125. ?>