I have a JQuery code like this:
// Validation to avoid non alphanumeric characters from being typed
function alphanumeric(eventSource) {
var numaric = eventSource.val();
for (var j = 0; j < numaric.length; j++) {
var alphaa = numaric.charAt(j);
var hh = alphaa.charCodeAt(0);
// If the value contains non alphanumeric characters
if (!((hh > 47 && hh < 58) || (hh > 64 && hh < 91) || (hh > 96 && hh < 123))) {
eventSource.val(numaric.substring(0, j) + numaric.substring(j + 1, numaric.length));
}
}
}
I am trying to validate the special characters of a text box input.
But somehow, it also validates the space (space bar on keyboard), which the char code is 32.
Advice please, thanks.
Try this :