0

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

1 Answer 1

1

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.