Forum Academy Marketplace Showcase Pricing Features

Working with full youtube-link

Hi,

I’m trying to let my users upload a link to their youtube video and display it on their profiles. But I have to use the video-ID, which they often get that wrong.

I suppose I could extract the ID with RegEx, but it seems there must be an easier way?

The optimal solution would be if they could just input a full link.

Any ideas?

the Video.js plugin accepts youtube links if that suits your projects needs.

Regex is the way example

^.*(youtu.be\/|v\/|embed\/|watch\?|youtube.com\/user\/[^#]*#([^\/]*?\/)*)\??v?=?([^#\&\?]*).*

I limit the number of characters on the input to 11, people usually figure it out since they can’t paste the full url

to play your video on a web page, do the following:

  • Upload the video to YouTube
  • Take a note of the video id
  • Define an
  • Let the src attribute point to the video URL
  • Use the width and height attributes to specify the dimension of the player
  • Add any other parameters to the URL (see below)