Reputation: 5460
is there a way to give a form fileupload inputfield a regexp for the filename?
I tried it like that:
$image1 = $form1->addElement('file', 'image1', array(
'validators' => array(
array('Count', false, '1' ),
array('Size', false, '10MB'),
array('Extension', false, 'jpg'),
array('regex', false, '/^[a-z]\.jpg$/'),
),
'required' => false,
'label' => 'Image1(jpg/tif)'
));
But its not working...
Can anyone give me a hint?
TIA, Matt
Upvotes: 0
Views: 810
Reputation: 484
You could try with a Callback validator and have the regexp checked in the callback method:
$form1->getElement('file')->addValidator(new Zend_Validator_Callback('checkFilename'));
...
public function checkFilename($file = null, $formData = null) {
$filename = $file->getValue();
if (preg_match(/^[a-z]\.jpg$/, $filename)) {
return true;
}
return false;
}
Upvotes: 1