http://www.youtube.com/channel/UChh-akEbUM8_6ghGVnJd6cQ How to validate whether the URL is youtube URL or not?
Asked
Active
Viewed 297 times
-1
-
4Please search for answer on stackowerflow before posting a question. – algiecas Jul 05 '13 at 08:39
-
Try with Regular Expressions/RegEx. – Jul 05 '13 at 08:43
2 Answers
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