I want to validate a form using jQuery. Therefore, I need to check if the input field does not contain ("#validatename")several words, for example, “United States of America”, “United Kingdom” or “France”.
To ban the "United States of America" (I will see later an array with all the forbidden lines!), I have ...
$("#validatename").keyup(function()
{
var name = $("#validatename").val();
if(name != '')
{
if ($('#validatename:contains("United States of America")').length > 0)
{
$("#validatename").css({
"background-image": "url('no.png')"
});
}
else
{
$("#validlastname").css({
"background-image": "url('yes.png')"
});
}
}
}
... But this does not work: yes.pngalways displayed!
Any help or idea would be greatly appreciated!
Many thanks.
source
share