Generic class that allows only alpha numeric values in text
how to write a generic class that allows only alpha numeric values in text boxes
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mangesh GPosted Feb 1, 2017, 8:07 AM
$(this).keypress(function (event) {
if (!event.charCode) return true;
var part1 = this.value.substring(0, this.selectionStart);
var part2 = this.value.substring(this.selectionEnd, this.value.length);
if (!mask.test(part1 + String.fromCharCode(event.charCode) + part2))
return false;
});
};
$(document).ready(function() {
var mask = new RegExp('^[A-Za-z0-9 ]*$')
$("input").regexMask(mask)
});