I have obtained these codes from other stackoverflow pages to correct youtube links but they dont work for my url:
https://www.youtube.com/watch?v=r2dRQHJ-aAk
code:
<script>
$('#videoURL').focusout(function() {
var url = this.value;
var videoid = url.match(/(?:https?:\/{2})?(?:w{3}\.)?youtu(?:be)?\.(?:com|be)(?:\/watch\?v=|\/)([^\s&]+)/);
if(videoid != null) {
$('#videoURL').value('http://www.youtube.com/watch?v='+videoid[1]);
} else {
console.log("The youtube url is not valid.");
}
});
</script>
it always returns:
The youtube url is not valid