I want users to submit youtube URLs. I want to check "on the fly" if a youtube link is correct and change the text next to the input to OK if the check succeeds.
I managed to make a validation function but it doesn't work. What am I doing wrong?
UPDATE
It still doesnt work, it should say not ok when the URL is incorrect and OK when URL is correct while typing:
$('form #youtube').bind("change keyup input", validYT());
function validYT()
{
var url = $('form #youtube').val();
var p = /^(?:https?:\/\/)?(?:www\.)?youtube\.com\/watch\?(?=.*v=((\w|-){11}))(?:\S+)?$/;
if (url.match(p)) {
$('#ytInfo').removeClass().addClass('fieldok ').text('OK');
return true
}
else
{
$('#ytInfo').removeClass().addClass('fieldok ').text('NOT OK');
return false
}
}
HTML:
youtubelink<BR>
<input type="text" name="youtube" id ="youtube" value="" /><div id="ytlInfo">dd</div>