Skip to content

Instantly share code, notes, and snippets.

@fjcunha
Last active August 12, 2016 19:23
Show Gist options
  • Save fjcunha/a1f0ed347dfc94e2fac65c6ab2eecb83 to your computer and use it in GitHub Desktop.
Save fjcunha/a1f0ed347dfc94e2fac65c6ab2eecb83 to your computer and use it in GitHub Desktop.
//function to prepare the youtube embeded Url to use in iFrame src
$scope.trustSrc = function(src) {
var url = src.replace("watch?v=", "embed/");
url = src.replace("youtu.be/", "youtube.com/embed/"); //if cpied link by youtube app
return $sce.trustAsResourceUrl(url);
}
//validate a youtube Url
$scope.validateYoutubeUrl = function (url)
{
if(url == null){
console.log("Not Valid Url...");
return false;
}
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=|\?v=)([^#\&\?]*).*/;
var match = url.match(regExp);
if (match && match[2].length == 11) {
// Do anything for being valid
console.log("Valid URL...");
return true;
}
else {
// Do anything for not being valid
console.log("Not Valid Url...");
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment