I borrowed a bit of code from this question (see reply 4):
how do i block or restrict special characters from input fields with jquery?
However, upon using the code, it appears, that although it does the validation as you type neatly, it does not allow you to edit anything you have entered.
$('input').bind('keypress', function (event) {
var regex = new RegExp("^[a-zA-Z0-9]+$");
var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
if (!regex.test(key)) {
event.preventDefault();
return false;
}});
I am a bit confused, I have tried to adjust it by changing the keypress to keyup but this just stops the validation from working. Any pointers would be graciously accepted.