/**
  * @param Field $field The field instance to check against
  * @return bool
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     return is_numeric($field->getValue());
 }
 /**
  * @param Field $field
  * @return bool
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     $fieldValue = $field->getValue();
     $emailValid = filter_var($fieldValue, FILTER_VALIDATE_EMAIL);
     if ($emailValid === false) {
         return false;
     }
     if ($this->checkMx === false) {
         return true;
     }
     $domain = substr($fieldValue, strrpos($fieldValue, '@') + 1);
     $mxRecords = array();
     if (getmxrr(idn_to_ascii($domain), $mxRecords) === true) {
         return true;
     }
     // Port 25 fallback check if there's no MX record
     $aRecords = dns_get_record($domain, DNS_A);
     if (count($aRecords) <= 0) {
         return false;
     }
     $connection = @fsockopen($aRecords[0]['ip'], 25);
     if (is_resource($connection) === true) {
         fclose($connection);
         return true;
     }
     return false;
 }
 /**
  * @param Field $field The field instance to check against
  * @return bool
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     return filter_var($field->getValue(), FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND) !== false || filter_var($field->getValue(), FILTER_VALIDATE_FLOAT, array('flags' => FILTER_FLAG_ALLOW_THOUSAND, 'options' => array('decimal' => ','))) !== false;
 }
Example #4
0
 public function isValueEmpty()
 {
     if (parent::isValueEmpty() === true) {
         return true;
     }
     if (is_array($this->value) === true) {
         return !(isset($this->value['day']) !== false && mb_strlen($this->value['day']) > 0 || isset($this->value['month']) !== false && mb_strlen($this->value['month']) > 0 || isset($this->value['year']) !== false && mb_strlen($this->value['year']) > 0);
     }
     return false;
 }
 /**
  * @param Field $field
  * @return bool
  * @throws \UnexpectedValueException
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     $fieldValue = $field->getValue();
     if (is_scalar($fieldValue) === true) {
         return $fieldValue >= $this->minValue;
     } else {
         throw new \UnexpectedValueException('Could not handle field value for rule ' . __CLASS__);
     }
 }
 /**
  * @param Field $field
  * @return bool
  * @throws \UnexpectedValueException
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     $fieldValue = $field->getValue();
     if (is_scalar($fieldValue) === true) {
         return $this->checkValueLengthAgainst(mb_strlen($fieldValue));
     } elseif (is_array($fieldValue) === true || $fieldValue instanceof \ArrayObject) {
         return $this->checkValueLengthAgainst(count($fieldValue));
     } else {
         throw new \UnexpectedValueException('Could not handle field value for rule ' . __CLASS__);
     }
 }
 /**
  * @param Field $field The field instance to check against
  * @throws \UnexpectedValueException
  * @return bool
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     $fieldValue = $field->getValue();
     if (is_scalar($fieldValue) === true) {
         return in_array($fieldValue, $this->validValues);
     } elseif (is_array($fieldValue) === true || $fieldValue instanceof \ArrayObject) {
         return count(array_diff($fieldValue, $this->validValues)) === 0;
     } else {
         throw new \UnexpectedValueException('Could not handle field value for rule ' . __CLASS__);
     }
 }
 /**
  * @param Field $field The field instance to check against
  * @return bool
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     $fldValue = $this->ignoreSurroundingSpaces ? trim($field->getValue()) : $field->getValue();
     $fldValue = preg_replace(array('@^[a-z]+://@i', '@^www\\.@i'), null, $fldValue);
     if (($lastPoint = strrpos($fldValue, '.')) === false) {
         return false;
     }
     if ($this->publicTld === true && strlen(substr($fldValue, $lastPoint + 1)) < 2) {
         return false;
     }
     return filter_var('http://' . idn_to_ascii($fldValue), FILTER_VALIDATE_URL) !== false;
 }
Example #9
0
 public function isValueEmpty()
 {
     if (parent::isValueEmpty() === true) {
         return true;
     }
     // @TODO make it nicer
     if ($this->isValidFileArray($this->value) === true) {
         return isset($this->value[self::VALUE_ERROR]) === false || $this->value[self::VALUE_ERROR] === UPLOAD_ERR_NO_FILE;
     }
     foreach ($this->value as $i => $fileInfo) {
         if ($fileInfo[self::VALUE_ERROR] === UPLOAD_ERR_NO_FILE) {
             continue;
         }
         return false;
     }
     return true;
 }
Example #10
0
 /**
  * @param Field $field The field instance to check against
  * @throws \UnexpectedValueException
  * @return bool
  */
 public function validate(Field $field)
 {
     if ($field->isValueEmpty() === true) {
         return true;
     }
     $fieldValue = $field->getValue();
     if (is_scalar($fieldValue) === true) {
         return $this->checkAgainstPattern($fieldValue);
     } elseif (is_array($fieldValue) === true || $fieldValue instanceof \ArrayObject) {
         foreach ($fieldValue as $value) {
             if ($this->checkAgainstPattern($value) === false) {
                 return false;
             }
         }
         return true;
     } else {
         throw new \UnexpectedValueException('The field value is neither scalar nor an array');
     }
 }
Example #11
0
 /**
  * @param Field $field
  * 
  * @return bool
  * 
  * @throws \UnexpectedValueException
  */
 public function validate(Field $field)
 {
     return !$field->isValueEmpty();
 }