/** * 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); } }
/** * 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'); } }
/** * 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'); } }
/** * 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'); } }
/** * 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'); } }
/** * 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); } }
/** * 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'); } }