正则表达式jquery

1 regex jquery

我想用min char = 5,max = 20验证一个texbox,允许字母和数字,只有3个特殊字符!@使用普通jQuery(没有插件)

function chkText() {
            $(".cssText").each(function() {
// add regex condition here in an IF statement
});
}
Run Code Online (Sandbox Code Playgroud)

Gum*_*mbo 6

这应该这样做:

function chkText() {
    $(".cssText").each(function() {
        if (/^[A-Za-z0-9!@#]{5,20}$/.test(this.value)) {
            // valid input value
        } else {
            // invalid input value
        }
    });
}
Run Code Online (Sandbox Code Playgroud)