Tuesday 1 October 2013

How to check the valid Youtube URL ?

// Here, The simple way to valid YouTube url in Appcelerator.

// Typically, the thing that most people want is the youtube video ID valid or not. 

// Some one also check that front part youtube.com/ that one very easy in appcelerator.

Here , some code

 var _videoUrl = "youtube.com/watch?v=FhnMNwiGg5M";
 var _videoUrlNotValid = "go.com/watch?v=FhnMNwiGg5M";

var matches = _videoUrl.match(/((http|https):\/\/)?(www\.)?(youtube\.com)(\/)?([a-zA-Z0-9\-\.]+\/?/);

var matches = _videoUrlNotValid.match(/((http|https):\/\/)?(www\.)?(youtube\.com)(\/)?([a-zA-Z0-9\-\.]+)\/?/);

  if (matches) {
        alert('valid youtube URL');
    }else{
        alert('Not valid');
    }

Output :)

1) _videoUrl is valid
2) _videoUrlNotValid not valid

Hope it helps you , i use this in Appcelerator and it works for me.

No comments:

Post a Comment