Regular expression to validate embed youtube url format


I want to validate format of embed youtube url for input field.

Allowed format =>

Not allowed format =>

below regular expression not validating allowed format


public static function isValidYoutubeUrl($url)
        return preg_match('/^http:\/\/(?:www\.)?\/embed\/[A-z0-9]',$url);

Any idea?


First of all your regexp tries to match to HTTP url and the provided URL is HTTPS. Also you might wanna add + in the end so it will match one or more characters after embed instead of one character.

This do it for you?

If you wanna match both https and http you could use:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.