Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7974203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:18:17+00:00 2026-06-04T08:18:17+00:00

I am trying to check whether a url is a valid youtube video URL

  • 0

I am trying to check whether a url is a valid youtube video URL and get the youtube video ID from it, so far I am using a simple javascript split function in order to achieve this, however this has some minor disadvantages as youtube has multiple URL’s.

I have been viewing other stackoverflow threads however all of them only support 1 specific URL which is not what I need.

I need something that matches all these URL’s:

http(s)://www.youtu.be/videoID

http(s)://www.youtube.com/watch?v=videoID

(and optionally any other short URL’s which the script automatically detects whether it contains a youtube video)

Any ideas which can be handled by the browser quick/efficient is greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:18:19+00:00Added an answer on June 4, 2026 at 8:18 am

    Try this:

    var url = "...";
    var videoid = url.match(/(?:https?:\/{2})?(?:w{3}\.)?youtu(?:be)?\.(?:com|be)(?:\/watch\?v=|\/)([^\s&]+)/);
    if(videoid != null) {
       console.log("video id = ",videoid[1]);
    } else { 
        console.log("The youtube url is not valid.");
    }
    

    see regex:

    /
    (?:https?:\/{2})? // Optional protocol, if have, must be http:// or https://
    (?:w{3}\.)?      // Optional sub-domain, if have, must be www.
    youtu(?:be)?  // The domain. Match 'youtu' and optionally 'be'. 
    \.(?:com|be) // the domain-extension must be .com or .be
    (?:\/watch\?v=|\/)([^\s&]+) //match the value of 'v' parameter in querystring from 'watch' directory OR after root directory, any non-space value.
    /
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to check whether a URL is from the same domain with jQuery
can anyone help me in trying to check whether JavaScript is enabled in client
I was trying to check whether the port is opened or not using powershell
I'm trying to check whether a function exists or not but I keep getting
I'm trying to check whether an URL returns 404, 403 etc when including a
I'm trying to check whether an input contains a URL either when a user
In my function template, I'm trying to check whether the type T is a
Using Javascript I'm trying to test whether or not a DIV with the id
I have been trying to check whether an NSInteger is odd or even. I
I am trying to find the fastest way to check whether a given number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.