kart kart - 6 months ago 5x
Javascript Question

how to check the valid Youtube url using jquery

In Jquery i want to check the specific url from youtube alone and show success status and others i want to skip by stating it as not valid url

var _videoUrl = "youtube.com/watch?v=FhnMNwiGg5M";
if (_videoUrl.contains("youtube.com"))
alert('Not Valid');

how to check with contains. or any other option to check the valid youtube url alone.


Typically, the thing that most people want is the youtube video ID. To simply match this, use the following regex.

var matches = _videoUrl.match(/watch\?v=([a-zA-Z0-9\-_]+)/);
if (matches)

Naturally, the regex could be expanded to include the entire youtube url, but if all you need is the ID, this is the most surefire way I've found.