ZF-10201: Zend_Validate_Regex will fail for certain valid regular expressions

Issue Type: Bug Created: 2010-07-21T23:37:32.000+0000 Last Updated: 2010-11-22T11:41:30.000+0000 Status: Resolved Fix version(s): - 1.10.7 (28/Jul/10)

Reporter: Feighen Oosterbroek (noondaysun) Assignee: Thomas Weidner (thomas) Tags: - Zend_Validate

Related issues: Attachments:


Have created a form using the following element

<pre class="highlight">
$this->addElement("password", "pass_word", array(
  array("Regex", true, array("[a-zA-Z0-9~!@$%^&*]{5,15}"))

I get the following error rendered in my browser

"Internal error while using the pattern '[a-zA-Z0-9~!@$%^&*]{5,15}'"

The regular expression matches correctly if I use a java pattern matching tool (Part of jEdit)

I have tracked the fault back to Zend/Validate/Regex.php Line 107

<pre class="highlight">
 * Sets the pattern option
 * @param  string $pattern
 * @throws Zend_Validate_Exception if there is a fatal error in pattern matching
 * @return Zend_Validate_Regex Provides a fluent interface
public function setPattern($pattern)
 $this->_pattern = (string) $pattern;
 $status         = @preg_match($this->_pattern, "Test"); **** This is line 107 ****
 if (false === $status) {
  require_once 'Zend/Validate/Exception.php';
  throw new Zend_Validate_Exception("Internal error while using the pattern '$this->_pattern'");

 return $this;

As you can see the subject of preg_match will never pass my regular expression. I know that workarounds exist. I could daisy chain the regex validator with the stringLength validator or I could alter my regex


Posted by Hendri Smit (hendri.smit) on 2010-07-22T02:57:05.000+0000

Your regex pattern doesn't have any delimiters so it is invalid. That's why the exception is thrown. The preg_match function will only return false if the pattern is incorrect. It returns 0 if no match was found.

This is not a bug. Read for more info on regular expressions in PHP.

Posted by Feighen Oosterbroek (noondaysun) on 2010-07-23T03:32:01.000+0000

I know. I had posted the bug by the time I had realised why it was returning false, and couldn't find a way to resolve the bug myself

Posted by Thomas Weidner (thomas) on 2010-07-24T06:43:41.000+0000

Closing as non issue according to the responses

Posted by Thomas Weidner (thomas) on 2010-11-22T11:41:30.000+0000

Correct fix version as it has been deleted unintentionally by another user

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.