jquery - Javascript format array with regex youtube video ids -
apologies in advance know there many answers question have not been successful implementing of given answers. being said, let's issue.
i have table containing text inputs user enters youtube video ids 
 onsubmit javascript create array containing these youtube video ids 
 if user enters youtube url, array breaks
quick solution 
 if can me regex validation work user alerted , correct input start
ideal solution 
 i'm not fond of alerting users , making them change they've entered bad user experience if feeling helpful today , show me how take enter , strip out url bits , push youtube video id array super wonderful :)
example: if user entered
["https://www.youtube.com/watch?v=k1cscqoj1da", "https://youtu.be/wij1sfrgmds", "iiszg-spuuo"] the code format inputs , final usersongs array be:
["k1cscqoj1da", "wij1sfrgmds", "iiszg-spuuo"] 
here fiddle http://jsfiddle.net/1qlr9n2j/
as can see, alert says no match when 2 of inputs invalid entries
you can use following match:
.*?([\w-]+)$ and replace $1.
see demo
js code:
var rx = /.*?([\w-]+)$/; (var = 0; < usersongs.length; i++) {         usersongs[i] = usersongs[i].replace(rx, '$1'); } alert(usersongs); 
Comments
Post a Comment