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

1 Answer 1

6

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
        }
    });
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.