[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/data/validator/rules/ -> ipcidrformatrule.class.php (source)

   1  <?php
   2  
   3      lt_include(PLOG_CLASS_PATH."class/data/validator/rules/regexprule.class.php");
   4  
   5      define( "IP_CIDR_FORMAT_RULE_REG_EXP", "^([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})/([0-9]{1,2})$");
   6      define( "ERROR_RULE_IP_CIDR_FORMAT_WRONG", "error_rule_ip_cidr_format_wrong");
   7  
   8      /**
   9       * \ingroup Validator_Rules
  10       *
  11       * Returns true if a given IP address is in valid CIDR format (Classless Inter-Domain Routing) These addresses
  12       * should have the following format: 
  13       *
  14       * <pre>xxx.yyy.zzz.www</pre>
  15       *
  16       * where each one of the elements is an integer between 0 and 255.
  17       */
  18      class IpCidrFormatRule extends RegExpRule
  19      {
  20          /**
  21           * Initializes the rule
  22           */
  23          function IpCidrFormatRule()
  24          {
  25              $this->RegExpRule(IP_CIDR_FORMAT_RULE_REG_EXP, false);
  26          }
  27  
  28          /**
  29           * Retursn true if the given IP address is in valid CIDR format
  30           *
  31           * @param value the IP address to validate
  32           */
  33          function validate($value)
  34          {
  35              if (!ereg($this->_regExp, $value, $regs))
  36              {
  37                  $this->_setError(ERROR_RULE_IP_CIDR_FORMAT_WRONG);
  38                  return false;
  39              }
  40              else if ($regs[1] > 255 || $regs[2] > 255 || $regs[3] > 255 || $regs[4] > 255 || $regs[5] > 32)
  41              {
  42                  $this->_setError(ERROR_RULE_IP_CIDR_FORMAT_WRONG);
  43                  return false;
  44              }
  45              else
  46              {
  47                  $this->_setError(false);
  48                  return true;
  49              }
  50          }
  51      }
  52  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics