how to check the valid Youtube url using jquery

后端 未结 8 743
心在旅途
心在旅途 2020-12-10 14:02

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          


        
相关标签:
8条回答
  • 2020-12-10 14:41

    You may try using a regular expression:

    var url = 'youtube.com/watch?v=FhnMNwiGg5M';
    var isyouTubeUrl = /((http|https):\/\/)?(www\.)?(youtube\.com)(\/)?([a-zA-Z0-9\-\.]+)\/?/.test(url);
    
    0 讨论(0)
  • 2020-12-10 14:41
    var regexp = /^(?:https?:\/\/)?(?:www\.)?youtube\.com\/watch\?(?=.*v=((\w|-){11}))(?:\S+)?$/;
    
    var matches_array = video_url.match(regexp);
    
    if(matches_array == null)
    
    {
    
                    alert("Enter youtube url");
    
                    return false;
    
    }
    
    0 讨论(0)
提交回复
热议问题