Strip bad characters from textarea as you type with jquery.

[code language=”js”]
<script language=’javascript’>
/*
* This function does some client side input validation. Automatically removing
* Bad characters before they cause a problem. Additional validation is done on the
* server.

* We’re also hacking the onpaste event.
*/
$(document).ready(function(){
//set keyup event
$("body").keyup(function(){
if ($("#body").val().match(/[^a-zA-Z0-9 n.,?]/g)) {
$("#body").val($("#body").val().replace(/[^a-zA-Z0-9 n.,?]/g, ”));
}//end if
}); // end keyup

$(document).bind(‘paste’, function(e){
if ($("#body").val().match(/[^a-zA-Z0-9 n.,?]/g)) {
$("#body").val($("#body").val().replace(/[^a-zA-Z0-9 n.,?]/g, ”));
}//end if
})

});// end docready
</script>
[/code]

This entry was posted in Code and tagged , , , .

Post a Comment

You must be logged in to post a comment.