Note that there are some explanatory texts on larger screens.

plurals
  1. POzf2 formFilter regex howto
    primarykey
    data
    text
    <p>Using zendframework v2, I have run into a problem with a regex validator on a field created by the Form factory. All other fields (using the same pattern) work without a problem.</p> <p>Any tips, or pointers is appreciated.</p> <pre><code> $inputFilter-&gt;add($factory-&gt;createInput([ 'name' =&gt; 'organizationName', 'filters' =&gt; array( array('name' =&gt; 'StripTags'), array('name' =&gt; 'StringTrim'), ), 'validators' =&gt; array( array( 'name' =&gt; 'NotEmpty', 'options' =&gt; array( 'messages' =&gt; array( \Zend\Validator\NotEmpty::IS_EMPTY =&gt; 'Organization name field is empty', ), ), ), array( 'name' =&gt; 'Regex', 'options' =&gt; array( 'pattern' =&gt; '/^[a-z0-9 &amp;-_\.,@]{3,25}$/i', 'messages' =&gt; array( \Zend\Validator\Regex::INVALID =&gt; 'Invalid input, only a-z, 0-9 &amp; - _ . characters allowed', ), ), ), array ( 'name' =&gt; 'StringLength', 'options' =&gt; array( 'encoding' =&gt; 'UTF-8', 'min' =&gt; '2', 'max' =&gt; '25', 'messages' =&gt; array( \Zend\Validator\StringLength::TOO_SHORT =&gt; 'Organization name field must be at least 8 characters in length', \Zend\Validator\StringLength::TOO_LONG =&gt; 'Organization name field must be no longer than 25 characters in length', ), ), ), ), ])); </code></pre> <p>Additional details: I am using the ZF2 to generate a <a href="https://github.com/jas-/myTFH-ZF2/blob/master/vendor/MyTFH/src/MyTFH/Form/RegisterForm.php" rel="nofollow">form</a>, I also create a <a href="https://github.com/jas-/myTFH-ZF2/blob/master/vendor/MyTFH/src/MyTFH/Form/RegisterValidator.php" rel="nofollow">validation filter</a> and then use the <a href="https://github.com/jas-/myTFH-ZF2/blob/master/vendor/MyTFH/src/MyTFH/Controller/RegisterController.php" rel="nofollow">controller</a> to handle proper form submissions.</p> <p>The problem I am having is with the above inputFilter object that handles the "organizationName" regex filter.</p> <p>It seems that although the regex patter I use both in the form definition and the input filter of <em>[a-z0-9 &amp;-_.,@]{3,25}</em> does not handle the string <em>Intl. Widgets Inc.</em> even though I do not get an error message from $form->getMessages() etc.</p> <p>Color me stumpted</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload