tags:

views:

90

answers:

1

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
});
}
+4  A: 

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
        }
    });
}
Gumbo