Exemple #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);
     }
 }
Exemple #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');
     }
 }
Exemple #3
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');
     }
 }
Exemple #4
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');
     }
 }
Exemple #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');
     }
 }
Exemple #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);
     }
 }
Exemple #7
0
 /**
  * Imports the value and returns a unix timestamp (the number of seconds
  * since the epoch.)
  *
  * @param string $value
  * @return int the date/time as a unix timestamp
  */
 public function import_value($value)
 {
     return strptime(strstr(parent::import_value($value), '-', '/'), '%d/%m/%Y');
 }
Exemple #8
0
 /**
  * @param array $validators a list of callbacks to validate the field data
  * @param array $attributes a list of key/value pairs representing HTML attributes
  */
 public function __construct(array $validators = array(), array $attributes = array())
 {
     parent::__construct('', 25, 255, $validators, $attributes);
 }
Exemple #9
0
 /**
  *
  * @param string $label the field's text label
  * @param int $size the field's size attribute
  * @param int $max_length the maximum size in characters
  * @param callback $hash_function a (string) function or array (instance, string method) callback
  * @param array $validators a list of callbacks to validate the field data
  * @param array $attributes a list of key/value pairs representing HTML attributes
  */
 public function __construct($label, $size, $max_length, $hash_function, array $validators = array(), array $attributes = array())
 {
     $this->hash_function = $hash_function;
     parent::__construct($label, $size, $max_length, $validators, $attributes);
 }