I have a field and want to prevent some illegal characters while showing the user as he types. How can I do this in follow example?
$(\'input\').bind(\"change
You may use the indexOf to determine if a string contains a certain char...
vowels = array('"', "<", ">", "&");
$('input').bind("change keyup", function()
{
var val = $(this).attr("value");
var illegal = '';
$(vowels).each(function()
{
if(val.indexOf(this)!=-1)
{
illegal= this;
break;
}
});
if(illegal != '')
{
$(this).css("background", "red");
val = val.replace(illegal, "");
$(this).attr("value", val)
}
});