I'm currently trying to restrict users so they can only input letters or numbers in a textbox and if anything other than letters or numbers is typed in I want to remove the value.
So my regex looks like ^[a-zA-Z0-9]+$
and the whole jQuery functions looks as follows:
$("#myInputField").keyup(function (e) {
if (/^[a-zA-Z0-9]+$/.test(this.value)) {
this.value = this.value.replace(/^[a-zA-Z0-9]+$/, '');
}
});
but this seems to be doing the opposite. So if I type a number or letter in then it's replaced and it's allowing all the other characters. Can someone tell me where I'm going wrong please.