-2

I would like to check the url that the user is saving and specially that it needs to be in a special format so i can use it at a later stage. The input field is to save a youtube video link and i would like to make sure that it is an actual youtube link or else present the user with an error stating it is not the proper format.

https://www.youtube.com/watch?v=y4Yp3-llWDs

I need to make sure that the beginning part of the url is proper always starting with this: https://www.youtube.com/watch

What would be the best way to go about this? regex?

072et
  • 345
  • 2
  • 8
  • 21

1 Answers1

0
var url = 'https://www.YouTube.com/watch'
if (/^https:\/\/www.youtube.com\/watch/i.test(url)) {
  console.log('Valid YouTube URL Detected')
} else {
  console.error('Invalid YouTube URL Detected')
}
anthumchris
  • 8,245
  • 2
  • 28
  • 53