Reputation:
I want to validate a texbox with min char=5, max=20, allow alphabet and numbers and only 3 special characters !@# using plain jQuery (no plugin)
function chkText() {
$(".cssText").each(function() {
// add regex condition here in an IF statement
});
}
Upvotes: 1
Views: 3466
Reputation: 655189
This should do it:
function chkText() {
$(".cssText").each(function() {
if (/^[A-Za-z0-9!@#]{5,20}$/.test(this.value)) {
// valid input value
} else {
// invalid input value
}
});
}
Upvotes: 6