I check the text box in my form as follows:
$name = new Zend_Form_Element_Text('name'); $name->setLabel('First Name:') ->setRequired(true) ->addFilter(new Zend_Filter_StringTrim()) ->addValidator('regex',true,array('/^[(a-zA-Z0-9)]+$/')) ->addErrorMessage('Please enter a valid first name');
What I'm trying to accomplish is how can I display a meaningful error message? For example: if the name is โXYZ-โ, how can I display โ- not allowed by nameโ.
Is there a way by which I can access which character the regular expression fails to execute? Would you recommend anything else?
I was thinking of writing a custom validator, but the regex is pretty simple, so I don't see the point. I could not find decent documentation for the zend 'regex' validator anywhere.
If I do not override the default error message, I just get something like: ';;; hhbhbhb 'does not match the pattern' / ^ [(a-zA-Z0-9)] + $ / '- which I obviously do not want to show to the user.
I would be grateful for your materials.
php regex zend-framework zend-form
Mallika iyer
source share