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
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Mangesh GRank #294 · 8.6K reputationPosted Feb 1, 2017, 3:07 AM EST
$(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)
});