Hi all:
I'm banging my head with the following validation:

                                                    'filters' => array(

'StringTrim',
                                                                      ),
                                                    'validators' => array(

array('Regex', $regexAlnumPlus),

'allowEmpty' => false,

'presence' => 'required',

'messages' => array(

'regexNotMatch' => 'First name contains illegal characters. Only ' .
$regexAlnumPlusMessage . ' are allowed!',

),

The regex is:

                list($regexAlnumPlus, $regexAlnumPlusMessage) =
array("/^[a-zA-Z0-9 .,'\-_]*$/", 'a-z, A-Z, 0-9, -, _, ., comma, space and
single quotes');

The issue is that it allows empty fields. I could use the following regex:

                 $regexPatternAndMessage = array("/^[a-zA-Z0-9 .,'\-_]+?$/",
'a-z, A-Z, 0-9, -, _, ., comma, space and single quotes');

I'd prefer to get a "Field can not be empty message" instead of the pattern
match message.

Checked the code and it seems like Zend_Filter_Input only checks for empty
if there hasn't been a validation (line 642:
$validatorRule[self::VALIDATOR_CHAIN_COUNT] = $i; and then 736 till 743:

                        if ($validatorRule[self::ALLOW_EMPTY] == true) {
                            continue;
                        }
                        if ($validatorRule[self::VALIDATOR_CHAIN_COUNT] ==
0) {
                            $notEmptyValidator =
$this->_getValidator('NotEmpty');

$notEmptyValidator->setMessage($this->_getNotEmptyMessage($validatorRule[self::RULE],
$fieldKey));

$validatorRule[self::VALIDATOR_CHAIN]->addValidator($notEmptyValidator);
                        }

Any insight would be greatly appreciated!
TIA

Gunter

Reply via email to