-1

http://www.youtube.com/channel/UChh-akEbUM8_6ghGVnJd6cQ How to validate whether the URL is youtube URL or not?

2 Answers2

1

You can check if URL contains the word "http://www.youtube.com" using .indexOf()

var url = 'http://www.youtube.com/channel/UChh-akEbUM8_6ghGVnJd6cQ';
if (url.indexOf('http://www.youtube.com') > -1) {
  alert( "true");
} else {
  alert( "false");
}
Praveen
  • 55,303
  • 33
  • 133
  • 164
0

Something like this:

var url = "http://www.youtube.com/channel/UChh-akEbUM8_6ghGVnJd6cQ";
var isyoutube = /\www\.youtube\.com/.test(url);

isyoutube gives you true or false depending if the URL is Youtube or not.

But as someone else already mentioned you should try and find it first. It's so easy to find. And also, Youtube has different URLs like http://www.youtu.be so my example will not always work.

putvande
  • 15,068
  • 3
  • 34
  • 50