示例#1
0
 /**
  * Validates that the value matches the regular expression.
  *
  * @param string $value
  * @return null
  * @throws Phorm_ValidationError
  */
 public function validate($value)
 {
     parent::validate($value);
     if (!filter_var($value, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $this->regex)))) {
         throw new Phorm_ValidationError($this->message);
     }
 }
示例#2
0
 /**
  * Validates that the value is a valid email address.
  *
  * @param string $value
  * @return null
  * @throws Phorm_ValidationError
  */
 public function validate($value)
 {
     parent::validate($value);
     if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
         throw new Phorm_ValidationError('field_invalid_email');
     }
 }
示例#3
0
 /**
  * Validates that the value is alpha only.
  *
  * @param string $value
  * @return null
  * @throws Phorm_ValidationError
  */
 public function validate($value)
 {
     $value = parent::validate($value);
     if (preg_match('/[0-9\\s]*/iu', $value)) {
         throw new Phorm_ValidationError('field_invalid_alpha');
     }
 }
示例#4
0
 /**
  * Validates that the value is alpha or numeric only.
  *
  * @param string $value
  * @return null
  * @throws Phorm_ValidationError
  */
 public function validate($value)
 {
     $value = parent::validate($value);
     if (!preg_match('/^\\S+$/iu', $value)) {
         throw new Phorm_ValidationError('field_invalid_alphanum');
     }
 }
示例#5
0
 /**
  * Validates the the value is a valid URL (mostly).
  *
  * @param string $value
  * @return null
  * @throws Phorm_ValidationError
  */
 public function validate($value)
 {
     $value = parent::validate($value);
     if (!filter_var($value, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED)) {
         throw new Phorm_ValidationError('field_invalid_url');
     }
 }
示例#6
0
 /**
  * Validates that the value matches the sscanf format.
  *
  * @param string $value
  * @return null
  * @throws Phorm_ValidationError
  */
 public function validate($value)
 {
     parent::validate($value);
     $this->matched = sscanf($value, $this->format);
     if (empty($this->matched)) {
         throw new Phorm_ValidationError($this->message);
     }
 }
示例#7
0
 /**
  * Validates that the value is parsable as a date/time value.
  *
  * @param string $value
  * @return null
  * @throws Phorm_ValidationError
  */
 public function validate($value)
 {
     parent::validate($value);
     if (!filter_var($value, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([0-9]{2})[\\-|\\/]([0-9]{2})[\\-|\\/]([0-9]{4})$/')))) {
         throw new Phorm_ValidationError('field_invalid_datetime_format');
     }
     if (!strptime(strstr($value, '-', '/'), '%d/%m/%Y')) {
         throw new Phorm_ValidationError('field_invalid_datetime_format');
     }
 }