Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Not an Issue
-
Affects Version/s: 1.10.5
-
Fix Version/s: 1.10.7
-
Component/s: Zend_Validate
-
Labels:None
Description
Have created a form using the following element
form_signIn password element
$this->addElement("password", "pass_word", array( "label"=>"Password", "required"=>true, "validators"=>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
setPattern function
/** * 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
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 http://php.net/manual/en/book.pcre.php for more info on regular expressions in PHP.