Last active
August 12, 2016 19:23
-
-
Save fjcunha/a1f0ed347dfc94e2fac65c6ab2eecb83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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