Prado\Web\UI\WebControls\TRegularExpressionValidator::evaluateIsValid PHP Method

evaluateIsValid() public method

The validation succeeds if the input data matches the regular expression. The validation always succeeds if ControlToValidate is not specified or the regular expression is empty, or the input data is empty.
public evaluateIsValid ( ) : boolean
return boolean whether the validation succeeds
    public function evaluateIsValid()
    {
        if (($value = $this->getValidationValue($this->getValidationTarget())) === '') {
            return true;
        }
        if (($expression = addcslashes($this->getRegularExpression(), "/")) !== '') {
            $mods = $this->getPatternModifiers();
            return preg_match("/^{$expression}\$/{$mods}", $value);
        } else {
            return true;
        }
    }

Usage Example

 /**
  * Returns an array of javascript validator options.
  * @return array javascript validator options.
  */
 public function evaluateIsValid()
 {
     $value = $this->getValidationValue($this->getValidationTarget());
     $valid = $valid = is_string($value) && strlen($value) <= 254 && parent::evaluateIsValid();
     if ($valid && $this->getCheckMXRecord() && function_exists('checkdnsrr')) {
         if ($value !== '') {
             if (($pos = strpos($value, '@')) !== false) {
                 $domain = substr($value, $pos + 1);
                 return $domain === '' ? false : checkdnsrr($domain, 'MX');
             } else {
                 return false;
             }
         }
     }
     return $valid;
 }