如何使用jquery检查有效的Youtube网址 [英] how to check the valid Youtube url using jquery

查看:169
本文介绍了如何使用jquery检查有效的Youtube网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Jquery中,我想单独检查来自youtube的特定网址并显示成功状态以及我想跳过的其他网址,将其说明为无效网址

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('Valid'); 
} 
else
{ 
  alert('Not Valid');
} 

如何检查包含。或任何其他选项来单独检查有效的youtube网址。

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

推荐答案

通常,大多数人想要的是youtube视频ID 。要简单匹配,请使用以下正则表达式。

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)
{
    alert('valid');
}

当然,正则表达式可以扩展为包含整个youtube网址,但是如果所有你需要的是身份证,这是我找到的最可靠的方式。

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.

这篇关于如何使用jquery检查有效的Youtube网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆