0

i want to provide a option for user to add video from the following video sites

  1. Dailymotion
  2. Metacafe
  3. YouTube - JavaScript REGEX: How do I get the YouTube video id from a URL?
  4. Google Video
  5. Hulu
  6. Yahoo! Video
  7. Vimeo - Parsing a Vimeo ID using JavaScript?
  8. MySpace Videos

So would like to validate the data both in javascript as well as php. Do the url structure of these site change or they stay usually constant . Any suggestions are welcome .

EDIT: I have got some solution for a few and i have update the question . I want for others preferably Regex solution

Community
  • 1
  • 1
aWebDeveloper
  • 31,131
  • 35
  • 150
  • 224

3 Answers3

2

Lately youtube have provided link shortening features, so links like:

http://youtu.be/ol_75jFEpck are valid too.

So i guess this regex isn't 100% accurate any more )-: .

meeDamian
  • 1,073
  • 2
  • 11
  • 24
1

There's a regular expression for YouTube URLs in the Closure Library:

/https?:\/\/(?:[a-zA_Z]{2,3}.)?(?:youtube.com\/watch\?)((?:[\w\d-_\=]+&(?:amp;)?)*v(?:<[A-Z]+>)?=([0-9a-zA-Z-_]+))/i;

http://closure-library.googlecode.com/svn/docs/closure_goog_ui_media_youtube.js.source.html

luissquall
  • 1,519
  • 17
  • 12
0

constant.

you should use regexp to validate url

usual url format:

this is not regexp :D
http://[domain].com/?[some GET letter like 'v']=[alphanumeric id][&other stufff..]
http://youtube.com/watch?v=aBcDeFg&embed=true#comment1

the id ?v=abcdefg still the same all of the time, but this can be embedd, or maybe there is hash code in the url

Gergely Fehérvári
  • 7,405
  • 6
  • 43
  • 71