How do I write a custom validator for a zend form element with customized error messages?
- by Mallika Iyer
I have a question field with a list of allowed characters : A-Z,0-9,colon (:), question mark (?), comma(,), hyphen(-), apostrophe (').
I have the regex which works fine, in the fashion :
$question->addValidator('regex', true, array(<regular expresstion>))
The default error message is something like ''' does not match against pattern ''
I want to write a custom error message that says ' is not allowed in this field'
Is there a simple way to do it using the existing zend components that I'm missing?
Is writing a custom validator the only way to achieve what I'm trying to achieve?
If yes, how do I write a custom validator (I looked at the documentation and didn't quite understand how I can customize the error messages)
If there is any other way, I'd most appreciate that input too.
Thanks for taking the time to answer this!