How do I write a custom validator for a zend form element with customized error messages?
Posted
by Mallika Iyer
on Stack Overflow
See other posts from Stack Overflow
or by Mallika Iyer
Published on 2010-04-13T14:17:19Z
Indexed on
2010/04/14
3:53 UTC
Read the original article
Hit count: 443
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!
© Stack Overflow or respective owner