public function addCriteria($criteria, $type = null)
 {
     //self-identify criteria
     //regexp, which type of validator?
     switch ($type) {
         case __EZV_REGEXP:
         case __EZV_COMPEXP:
         case __EZV_DATE:
         case __EZV_CURRENCY:
             //all of these cases are fine, and we just pass through to data structure
             //add to parallell arrays
             $this->criteria_arr[$this->criteria_count++] = $criteria;
             $this->type_arr[$this->type_count++] = $type;
             return $this->criteria_count - 1;
         case __EZV_UNKNOWN:
         default:
             //check $criteria for regexp, numexp, date, currency
             $cev = new CompExpValidator();
             $rev = new RegExpValidator();
             $dev = new DateExpValidator();
             $tev = new TimeExpValidator();
             $cuev = new CurrencyExpValidator();
             if ($cev->isValidCriteria($criteria)) {
                 $this->criteria_arr[$this->criteria_count++] = $criteria;
                 $this->type_arr[$this->type_count++] = __EZV_COMPEXP;
                 return $this->criteria_count - 1;
             } else {
                 if ($rev->isValidCriteria($criteria)) {
                     $this->criteria_arr[$this->criteria_count++] = $criteria;
                     $this->type_arr[$this->type_count++] = __EZV_REGEXP;
                     return $this->criteria_count - 1;
                 } else {
                     if ($dev->isValidCriteria($criteria)) {
                         $this->criteria_arr[$this->criteria_count++] = $criteria;
                         $this->type_arr[$this->type_count++] = __EZV_DATEEXP;
                         return $this->criteria_count - 1;
                     } else {
                         if ($tev->isValidCriteria($criteria)) {
                             $this->criteria_arr[$this->criteria_count++] = $criteria;
                             $this->type_arr[$this->type_count++] = __EZV_TIMEEXP;
                             return $this->criteria_count - 1;
                         } else {
                             if ($cuev->isValidCriteria($criteria)) {
                                 $this->criteria_arr[$this->criteria_count++] = $criteria;
                                 $this->type_arr[$this->type_count++] = __EZV_CURRENCYEXP;
                                 return $this->criteria_count - 1;
                             } else {
                                 if ($dieSilently) {
                                     return false;
                                 } else {
                                     throw new Exception("Cannot determine criteria type");
                                     return false;
                                 }
                             }
                         }
                     }
                 }
             }
     }
 }
예제 #2
0
파일: validator.php 프로젝트: vazahat/dudex
 /**
  * Class constructor
  */
 public function __construct()
 {
     parent::__construct(UTIL_Validator::ALPHA_NUMERIC_PATTERN);
     $errorMessage = OW::getLanguage()->text('base', 'form_validator_url_error_message');
     if (empty($errorMessage)) {
         $errorMessage = 'Alphanumeric Validator Error!';
     }
     $this->setErrorMessage($errorMessage);
 }
예제 #3
0
 function testTwoDomainsInvalid()
 {
     $validator = new RegExpValidator();
     $this->assertFalse($validator->validate("*****@*****.**", __EZV_EMAIL_REGEXP));
 }