Last active
August 29, 2015 14:10
-
-
Save wpcastil/45db842d01dafaf21ebc to your computer and use it in GitHub Desktop.
Valida se a url passada por parâmetro contém um id do Youtube válido.
This file contains hidden or 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
| /** | |
| * exemplo de funcionamento: http://regex101.com/r/kW4bU8/1 | |
| * Fará a comparação com expressão regular e no índice 3 do array, haverá o id do vídeo, que tem 11 caracteres | |
| * @method validarIdYoutube | |
| * @author Wiliam Felisiak Passaglia Castilhos [[email protected]] | |
| * @date 2014-11-21 | |
| * @param {string} url [url a ser analisada] | |
| * @return {boolean} [verdadeiro se for uma url que contenha um id válido] | |
| */ | |
| function validarIdYoutube(url){ | |
| var re = /^.*(youtu.be\/|v\/|u\/\w+\/|embed|e\/|watch\?v|\?v=|\&v=)([^#\&\?]{11,11}).*/gm; | |
| var id; | |
| var retorno = false; | |
| id = re.exec(url); | |
| if(id[2].length == 11){ | |
| retorno = true; | |
| } | |
| return retorno; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment