[ Index ]
 

Code source de PRADO 3.0.6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/framework/Web/UI/WebControls/ -> TRegularExpressionValidator.php (source)

   1  <?php
   2  /**
   3   * TRequiredFieldValidator class file
   4   *
   5   * @author Qiang Xue <qiang.xue@gmail.com>
   6   * @link http://www.pradosoft.com/
   7   * @copyright Copyright &copy; 2005 PradoSoft
   8   * @license http://www.pradosoft.com/license/
   9   * @version $Id: TRegularExpressionValidator.php 1397 2006-09-07 07:55:53Z wei $
  10   * @package System.Web.UI.WebControls
  11   */
  12  
  13  /**
  14   * Using TBaseValidator class
  15   */
  16  Prado::using('System.Web.UI.WebControls.TBaseValidator');
  17  
  18  /**
  19   * TRegularExpressionValidator class
  20   *
  21   * TRegularExpressionValidator validates whether the value of an associated
  22   * input component matches the pattern specified by a regular expression.
  23   *
  24   * You can specify the regular expression by setting the {@link setRegularExpression RegularExpression}
  25   * property. Some commonly used regular expressions include:
  26   * <pre>
  27   * French Phone Number: (0( \d|\d ))?\d\d \d\d(\d \d| \d\d )\d\d
  28   * French Postal Code: \d{5}
  29   * German Phone Number: ((\(0\d\d\) |(\(0\d{3}\) )?\d )?\d\d \d\d \d\d|\(0\d{4}\) \d \d\d-\d\d?)
  30   * German Postal Code: (D-)?\d{5}
  31   * Email Address: \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
  32   * Japanese Phone Number: (0\d{1,4}-|\(0\d{1,4}\) ?)?\d{1,4}-\d{4}
  33   * Japanese Postal Code: \d{3}(-(\d{4}|\d{2}))?
  34   * P.R.C. Phone Number: (\(\d{3}\)|\d{3}-)?\d{8}
  35   * P.R.C. Postal Code: \d{6}
  36   * P.R.C. Social Security Number: \d{18}|\d{15}
  37   * U.S. Phone Number: ((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}
  38   * U.S. ZIP Code: \d{5}(-\d{4})?
  39   * U.S. Social Security Number: \d{3}-\d{2}-\d{4}
  40   * </pre>
  41   *
  42   * Note, the validation succeeds if the associated input control contains empty input.
  43   * Use a {@link TRequiredFieldValidator} to ensure the input is not empty.
  44   *
  45   * @author Qiang Xue <qiang.xue@gmail.com>
  46   * @version $Id: TRegularExpressionValidator.php 1397 2006-09-07 07:55:53Z wei $
  47   * @package System.Web.UI.WebControls
  48   * @since 3.0
  49   */
  50  class TRegularExpressionValidator extends TBaseValidator
  51  {
  52      /**
  53       * Gets the name of the javascript class responsible for performing validation for this control.
  54       * This method overrides the parent implementation.
  55       * @return string the javascript class name
  56       */
  57  	protected function getClientClassName()
  58      {
  59          return 'Prado.WebUI.TRegularExpressionValidator';
  60      }
  61  
  62      /**
  63       * @return string the regular expression that determines the pattern used to validate a field.
  64       */
  65  	public function getRegularExpression()
  66      {
  67          return $this->getViewState('RegularExpression','');
  68      }
  69  
  70      /**
  71       * @param string the regular expression that determines the pattern used to validate a field.
  72       */
  73  	public function setRegularExpression($value)
  74      {
  75          $this->setViewState('RegularExpression',$value,'');
  76      }
  77  
  78      /**
  79       * This method overrides the parent's implementation.
  80       * The validation succeeds if the input data matches the regular expression.
  81       * The validation always succeeds if ControlToValidate is not specified
  82       * or the regular expression is empty, or the input data is empty.
  83       * @return boolean whether the validation succeeds
  84       */
  85  	public function evaluateIsValid()
  86      {
  87          if(($value=$this->getValidationValue($this->getValidationTarget()))==='')
  88              return true;
  89          if(($expression=$this->getRegularExpression())!=='')
  90              return preg_match("/^$expression\$/",$value);
  91          else
  92              return true;
  93      }
  94  
  95      /**
  96       * Returns an array of javascript validator options.
  97       * @return array javascript validator options.
  98       */
  99  	protected function getClientScriptOptions()
 100      {
 101          $options = parent::getClientScriptOptions();
 102          $options['ValidationExpression']=$this->getRegularExpression();
 103          return $options;
 104      }
 105  }
 106  
 107  ?>


Généré le : Sun Feb 25 21:07:04 2007 par Balluche grâce à PHPXref 0.7