<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>
Strip bad characters from textarea as you type with jquery.
Permanent link to this article: http://www.lukemacneil.com/2010/04/23/strip-bad-characters-from-textarea-as-you-type-with-jquery/
Recent Comments