3

Message: Internal error while using the pattern "(http://)?(www.)?(youtu)((be.com)|(.be))/.*"

$element = new Zend_Form_Element_Text($this->name);
$element->setRequired(true)
        ->setLabel(FileTypes::$names[$this->fileType])
        ->setDescription('Paste YouTube link here')
        ->setDecorators(FormDecorators::$simpleElementDecorators)
        ->addValidator('regex', false, '(http://)?(www\.)?(youtu)((be\.com)|(\.be))/.*');

Throws error even with simple regular expression.

3 Answers 3

1

Have you validated your regex as correct? Try it out in a regex tool, see if it generates any errors. A decent tool should tell you why your regex is wrong if it is invalid.

Most regexes I've seen are usually bookended with some kind of character, commonly '/'. The fact that yours isn't might have something to do with the error you're getting.

You should also bear in mind that whilst PHP's regex is similar to Perl, there are a few differences. They probably don't matter in this case, but you should be aware of them nonetheless. http://www.php.net/manual/en/reference.pcre.pattern.differences.php

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, i added strips and also escaped some slashes. help.
0

try this, you need to put your pattern in an array and include the delimiters.

$element = new Zend_Form_Element_Text($this->name);
                $element->setRequired(true)
                        ->setLabel(FileTypes::$names[$this->fileType])
                        ->setDescription('Paste YouTube link here')
                        ->setDecorators(FormDecorators::$simpleElementDecorators)
                        ->addValidator('regex', false, array(
                           'pattern' => '/(http://)?(www\.)?(youtu)((be\.com)|(\.be))/.*/'                                                                    
                         ));

Comments

0

Escape the slashes in http:

->addValidator('regex', false, '(http:\/\/)?(www\.)?(youtu)((be\.com)|(\.be))\/.*');

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.