public function __construct($options = array(), $messages = array()) { if (!isset($options['pattern'])) { $options['pattern'] = "/#[0-9abcdefABCDEF]{6}/"; } parent::__construct($options, $messages); }
public function __construct($options = array(), $messages = array()) { if (!isset($options['pattern'])) { $options['pattern'] = "#https?://[^\"\\s]+\\.[^\"\\s]+#"; } parent::__construct($options, $messages); }
/** * @see sfValidatorRegex */ protected function configure($options = array(), $messages = array()) { parent::configure($options, $messages); $this->setMessage('invalid', 'You email is invalid, please check again.'); $this->setMessage('min_length', 'This email "%value%" is too short (%min_length% characters min).'); $this->setOption('pattern', self::REGEX_EMAIL); }
/** * @see sfValidatorString */ protected function doClean($value) { if (!array_key_exists($this->getOption('algorithm'), $this->algorithms)) { throw new LogicException(__CLASS__ . ' does not support this algorithm'); } $algorithm = $this->algorithms[$this->getOption('algorithm')]; $this->setOption('pattern', '/^[a-f0-9]{' . $algorithm['length'] . '}$/i'); return parent::doClean($value); }
/** * @see sfValidatorRegex */ protected function doClean($value) { $clean = parent::doClean($value); $value = (double) $value; if ($value < 0 || $value > 8000) { throw new sfValidatorError($this, 'out_of_range', array('value' => $value)); } return $clean; }
protected function configure($options = array(), $messages = array()) { parent::configure($options, $messages); $this->setMessage('invalid', '"%value%" is not an valid ip address'); $this->setOption('pattern', ' ~^ ([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3} # ip address $~ix'); }
protected function doClean($value) { $clean = parent::doClean($value); if ($this->getOption('check_domain') && function_exists('checkdnsrr')) { $tokens = explode('@', $clean); if (!checkdnsrr($tokens[1], 'MX') && !checkdnsrr($tokens[1], 'A')) { throw new sfValidatorError($this, 'invalid', array('value' => $clean)); } } return $clean; }
/** * @see sfValidatorString */ protected function doClean($value) { $value = parent::doClean($value); // replace spaces with dots $value = str_replace(' ', '.', trim($value)); // replace .. and .# with . $value = preg_replace('|\\.([\\.\\#]+)|', '', $value); // must start with a . or a # if (!empty($value) && $value[0] !== '.' && $value[0] !== '#') { $value = '.' . $value; } return $value; }
/** * * value should be array * array('dynamic-bootp 0.0.0.0 0.0.0.0') * or * array('0.0.0.0 0.0.0.0') * * @see sfValidatorBase */ protected function doClean($value) { $choices = $this->getOption('choices'); if ($choices instanceof sfCallable) { $choices = $choices->call(); } if (!is_array($value)) { throw new sfValidatorError($this, 'type_error'); } $match_bootp = '/^' . self::$bootp_flag . '/'; foreach ($value as $v) { if (preg_match($match_bootp, $v)) { $ranges_data = explode(' ', $v, 3); if (count($ranges_data) != 3) { throw new sfValidatorError($this, 'invalid', array('value' => $v)); } $dyn_bootp = $ranges_data[0]; $from_ip = $ranges_data[1]; $to_ip = $ranges_data[2]; $validate_bootp = new sfValidatorRegex(array('pattern' => '#^' . self::$bootp_flag . '#'), array('invalid' => $this->getMessage('invalid'))); $validate_bootp->doClean($dyn_bootp); // should be dynamic bootp flag $ip = new ValidatorIP(); $ip->doClean($from_ip); $ip->doClean($to_ip); } else { $ranges_data = explode(' ', $v, 2); if (count($ranges_data) != 2) { throw new sfValidatorError($this, 'invalid', array('value' => $v)); } $from_ip = $ranges_data[0]; $to_ip = $ranges_data[1]; $ip = new ValidatorIP(); $ip->doClean($from_ip); $ip->doClean($to_ip); } } return $value; }
/** * @param array $options An array of options * @param array $messages An array of error messages * * @see sfValidatorRegex */ protected function configure($options = array(), $messages = array()) { parent::configure($options, $messages); $this->setOption('pattern', '~^ (https?|ftps?):// # http or ftp (+SSL) ( ([a-z0-9-]+\\.)+[a-z]{2,6} # a domain name | # or \\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3} # a IP address ) (:[0-9]+)? # a port (optional) (/?|/\\S+) # a /, nothing or a / with something $~ix'); }
protected function doClean($value) { //Truncar valor antes $clean = trim((string) $value); parent::doClean($clean); $length = function_exists('mb_strlen') ? mb_strlen($clean, $this->getCharset()) : strlen($clean); if ($this->hasOption('required') && $length == 0) { throw new sfValidatorError($this, 'required', array('value' => $value, 'required' => $this->getOption('required'))); } if ($this->hasOption('max_length') && $length > $this->getOption('max_length')) { throw new sfValidatorError($this, 'max_length', array('value' => $value, 'max_length' => $this->getOption('max_length'))); } return $clean; }
} catch (sfValidatorError $e) { $t->pass('->clean() throws an sfValidatorError if the value does not match the pattern'); $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); } $v = new sfValidatorRegex(array('pattern' => '/^[0-9]+$/', 'must_match' => false)); $t->is($v->clean('symfony'), 'symfony', '->clean() checks that the value does not match the regex if must_match is false'); try { $v->clean(12); $t->fail('->clean() throws an sfValidatorError if the value matches the pattern if must_match is false'); $t->skip('', 1); } catch (sfValidatorError $e) { $t->pass('->clean() throws an sfValidatorError if the value matches the pattern if must_match is false'); $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); } $v = new sfValidatorRegex(array('pattern' => new sfCallable('generate_regex'))); try { $v->clean('123'); $t->pass('->clean() uses the pattern returned by a sfCallable pattern option'); } catch (sfValidatorError $e) { $t->fail('->clean() uses the pattern returned by a sfCallable pattern option'); } // ->asString() $t->diag('->asString()'); $v = new sfValidatorRegex(array('pattern' => '/^[0-9]+$/', 'must_match' => false)); $t->is($v->asString(), 'Regex({ must_match: false, pattern: \'/^[0-9]+$/\' })', '->asString() returns a string representation of the validator'); // ->getPattern() $t->diag('->getPattern()'); $v = new sfValidatorRegex(array('pattern' => '/\\w+/')); $t->is($v->getPattern(), '/\\w+/', '->getPattern() returns the regular expression'); $v = new sfValidatorRegex(array('pattern' => new sfCallable('generate_regex'))); $t->is($v->getPattern(), '/^123$/', '->getPattern() returns a regular expression from a sfCallable');
/** * Available options: * * * protocols: An array of acceptable URL protocols (http, https, ftp and ftps by default) * * @param array $options An array of options * @param array $messages An array of error messages * * @see sfValidatorRegex */ protected function configure($options = array(), $messages = array()) { parent::configure($options, $messages); $this->addOption('protocols', array('http', 'https', 'ftp', 'ftps')); $this->setOption('pattern', new sfCallable(array($this, 'generateRegex'))); }
protected function configure($options = array(), $messages = array()) { parent::configure($options, $messages); $this->setMessage('invalid', 'This is not a valid hexadecimal color'); $this->setOption('pattern', '|^#?[\\dA-F]{6}$|i'); }
/** * @see sfValidatorString */ protected function doClean($value) { $value = parent::doClean($value); $value = trim(str_replace('.', ' ', $value)); return $value; }
/** * @see sfValidatorString */ protected function doClean($value) { $clean = md5(parent::doClean($value)); return $clean; }
/** * @see sfValidatorRegex */ protected function configure($options = array(), $messages = array()) { parent::configure($options, $messages); $this->setOption('pattern', '/^([^@\\s]+)@((?:[-a-z0-9]+\\.)+[a-z]{2,})$/i'); }
/** * @see sfValidatorRegex */ protected function configure($options = array(), $messages = array()) { parent::configure($options, $messages); // also accept 5 digits even if its not a valid organization number $this->setOption('pattern', '/(^\\d{9}$)|(^\\d{6}$)|(^\\d{5}$)/'); }
* This file is part of the symfony package. * (c) Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; $t = new lime_test(5, new lime_output_color()); // __construct() $t->diag('__construct()'); try { new sfValidatorRegex(); $t->fail('__construct() throws an RuntimeException if you don\'t pass a pattern option'); } catch (RuntimeException $e) { $t->pass('__construct() throws an RuntimeException if you don\'t pass a pattern option'); } $v = new sfValidatorRegex(array('pattern' => '/^[0-9]+$/')); // ->clean() $t->diag('->clean()'); $t->is($v->clean(12), '12', '->clean() checks that the value match the regex'); try { $v->clean('symfony'); $t->fail('->clean() throws an sfValidatorError if the value does not match the pattern'); $t->skip('', 1); } catch (sfValidatorError $e) { $t->pass('->clean() throws an sfValidatorError if the value does not match the pattern'); $t->is($e->getCode(), 'invalid', '->clean() throws a sfValidatorError'); } // ->asString() $t->diag('->asString()'); $t->is($v->asString(), 'Regex({ pattern: \'/^[0-9]+$/\' })', '->asString() returns a string representation of the validator');
public function configure($options = array(), $messages = array()) { parent::configure($options, $messages); $this->setOption('pattern', $this->getPasswordPattern()); $this->setMessage('invalid', 'The password is too weak. It must be at least 8 characters long AND contain at least 2 alphabetical characters AND 2 digital characters AND one symbol among !@#$%^&*-.'); }
/** * @see sfValidatorRegex */ protected function configure($options = array(), $messages = array()) { parent::configure($options, $messages); $this->setOption('pattern', self::REGEX_EMAIL); }
public function __construct($options = array(), $messages = array()) { return parent::__construct(array_merge($this->_options, $options), array_merge($this->_messages, $messages)); }