public function executeValidateRegexp() { $myValidator = new sfRegexValidator(); $myValidator->initialize($this->getContext(), array('match' => "Yes", 'pattern' => urldecode($this->getRequestParameter('pattern')))); $value = urldecode($this->getRequestParameter('value')); if (!$myValidator->execute($value, $error)) { exit(UtilsHelper::Localize('system.frontend.Validate_regexp_error')); } exit("ok"); }
public function executeValidateRegexp() { $myValidator = new sfRegexValidator(); $myValidator->initialize($this->getContext(), array('match' => "Yes", 'pattern' => urldecode($this->getRequestParameter('pattern')))); if (!$myValidator->execute(urldecode($this->getRequestParameter('value')), $error)) { exit('invalid data'); } exit("ok"); }
try { $v = new sfRegexValidator($context); $t->fail('->initialize() takes a mandatory "pattern" parameter'); } catch (sfValidatorException $e) { $t->pass('->initialize() takes a mandatory "pattern" parameter'); } $t->ok(new sfRegexValidator($context, array('pattern' => '/\d+/')), '->initialize() takes a "pattern" as a parameter'); $v = new sfRegexValidator($context, array('pattern' => '/\d+/', 'match_error' => 'my error message')); $value = 'a string'; $error = null; $v->execute($value, $error); $t->is($error, 'my error message', '->initialize() changes "$error" with a custom message if it returns false'); // ->execute() $t->diag('->execute()'); $v->initialize($context, array('pattern' => '/\d+/')); $value = 12; $error = null; $t->ok($v->execute($value, $error), '->execute() returns true if value match the pattern'); $t->is($error, null, '->execute() doesn\'t change "$error" if it returns true'); $value = 'a string'; $error = null; $t->ok(!$v->execute($value, $error), '->execute() returns false if value does not match the pattern'); $t->isnt($error, null, '->execute() changes "$error" with a default message if it returns false');