[Solved] testing if a link is a youtube link.


Though it would be better to add a clear question to the question, I just noticed the comment in this line of the provided code:

if(url.toLowerCase().indexOf("youtube") > 0)  // this is where my function fails.

You should check what var url = $("#<%=txtYoutubeLink.ClientID %>").val(); actually returns, because in case the url starts with youtube, the result of

url.toLowerCase().indexOf("youtube")

is 0.
indexOf() does not check if a substring is contained in another string, but returns the position (starting at 0), in case the substring is contained, or -1 in case the substring is not contained. Just adjust to

if(url.toLowerCase().indexOf("youtube") >= 0)

For reference: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf

solved testing if a link is a youtube link.