I would like to disallow people to writing character "#" on my input how can I achieve it ?
            Asked
            
        
        
            Active
            
        
            Viewed 232 times
        
    0
            
            
        - 
                    2How about RegEx validator class with a pattern like `[^#]` (http://framework.zend.com/manual/2.2/en/modules/zend.validator.set.html#regex)? What have you tried? Maybe you could just filter that input field instead of validating it? Some more info would be useful. – guessimtoolate Aug 17 '13 at 20:05
- 
                    Regex is good idea but when i'm using this pattern : [^#] the form is never valid, with or without #. – Siol Aug 18 '13 at 10:47
- 
                    Answer here http://stackoverflow.com/questions/5704061/php-reverse-preg-match this pattern working : /^(?:(?!#).)*$/i – Siol Aug 18 '13 at 11:30
1 Answers
1
            
            
        As @guessimtoolate suggested, since if you want to disallow only the sharp-character, then it's best to simply filter it out. Filters are run before Validation, therefore your workflow is like this:
- Get Field Value
- Remove all occurences of the character #
- Validate your field using your attached validators
The Filter you wanna be using is the Zend\Filter\PregReplace. In case you're providing your Filters/Validators via the provider-interface, then the array-notation should be the following (it's untested, so you may work around a little bit with it)
'filters' => array(
    array('name' => 'Zend\Filter\PregReplace', 'options' => array(
       'pattern'     => '/#/',
       'replacement' => ''
    )
)
 
    
    
        Sam
        
- 16,435
- 6
- 55
- 89
