I'm happy you posted this as I didn't find any reference to INVALID in
Zend_Validate_Regex.

I've been using the preset const values in the Zend_Validate(functions) as
reference for custom error messages.

Like this :

$fname = new Zend_Form_Element_Text('first_name');
$fname->setLabel('First Name')
        ->addValidator(
                'regex', // validator type
                true,   // break chain on fail
                array(
                        '/[a-z\'\-]/is',        // regex test
                        'messages' => array( // error messages
                                Zend_Validate_Regex::INVALID  => 'First Name
contains invalid characters.',
                                Zend_Validate_Regex::NOT_MATCH  => 'First
Name contains invalid characters.'
                        )
                )
        );

What's the difference between INVALID and NOT_MATCH and, why is the INVALID
not in the $_messageTemplates ?

Terre

~snip
-- \libary\Zend\Validate\Regex.php
-- @version    $Id: Regex.php 8064 2008-02-16 10:58:39Z thomas $
protected $_messageTemplates = array(
        self::NOT_MATCH => "'%value%' does not match against pattern
'%pattern%'"
    );
~snip

-----Original Message-----
From: Thomas Weidner [mailto:thomas.weid...@gmx.at] 
Sent: Thursday, July 09, 2009 9:23 AM
To: fw-general
Subject: Re: [fw-general] Zend_Validate_Regex issue

The regex validator has also a INVALID message which you did not set.
Which type has the value you want to validate ? Try a var_dump of the value.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message -----
From: "Bart McLeod" <mcl...@spaceweb.nl>
To: "fw-general" <fw-general@lists.zend.com>
Sent: Thursday, July 09, 2009 2:17 PM
Subject: [fw-general] Zend_Validate_Regex issue


> Hi all,
>
> I searched the mailing list and the issue tracker, but I can't find an 
> issue for this. However, I would like to double check with you all, before

> creating a new issue. Maybe I am just coding wrong or there already exists

> an issue that you can point me to.
>
> Here's the problem:
> I add a Regex validator to a form.
>
> I set the a custom message on Zend_Validate_Regex::NOT_MATCH.
>
> I do not get the custom message, but instead I get:
> "Invalid type given, value should be string, integer or float"
>
> Which makes no sense at all (at least to me).
>
> Anyone?
>
> My version is latest trunk, it also affects existing solutions that worked

> fine for months.
>
> The code:
>            $phoneValidator = new Zend_Validate_Regex($pattern);
>            $phoneValidator->setMessage("U mag de volgende tekens 
> gebruiken: + - ( ) een spatie en cijfers.", 
> Zend_Validate_Regex::NOT_MATCH );
>            $telephone->addValidator($phoneValidator);
>            $form->addElement($telephone);
>
> Regards,
>
> Bart McLeod 

Reply via email to