How can I customise Zend_Form regex error messages?

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-03-31T14:52:50Z Indexed on 2010/03/31 15:23 UTC
Read the original article Hit count: 517

I have the following code:

    $postcode = $form->createElement('text', 'postcode');
    $postcode->setLabel('Post code:');
    $postcode->addValidator('regex', false, 
        array('/^[a-z]{1,3}[0-9]{1,3} ?[0-9]{1,3}[a-z]{1,3}$/i'));
    $postcode->addFilters(array('StringToUpper'));
    $postcode->setRequired(true);

It creates an input field in a form and sets a regex validation rule and works just fine.

The problem is that the error message it displays when a user enters an invalid postcode is this:

'POSTCODE' does not match against pattern
    '/^[a-z]{1,3}[0-9]{1,3} ?[0-9]{1,3}[a-z]{1,3}$/i'

(where input was POSTCODE)

How can I change this message to be a little more friendly?

© Stack Overflow or respective owner

Related posts about zend-form

Related posts about regex