jQuery keyup() illegal characters
Posted
by FFish
on Stack Overflow
See other posts from Stack Overflow
or by FFish
Published on 2010-05-19T13:55:03Z
Indexed on
2010/05/19
14:10 UTC
Read the original article
Hit count: 275
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 keyup", function() {
var val = $(this).attr("value");
/*
if (val --contains-- '"') {
$(this).css("background", "red");
val = val.replace('"', "");
$(this).attr("value", val)
}
*/
$("p").html(val);
});
EDIT: I should put the illegal characters in an array
var vowels = new Array('"', "<", ">", "&");
© Stack Overflow or respective owner