jquery validata.js 使用出错?

问题:
1.不输入直接提交,输出true;
2.输入错误,有错误提示,但是输出true;
3.输入正确,没有错误提示,但是仍然输出true;
大家帮忙看看,哪里写错了啊?

<form action="" id="commentForm">
        <span>校验项</span><input type="text" id="name" class="checkUnameLen" name="" required/>
        <input type="button" onclick="check()" value="校验"/>
    </form>

js文件

function check(){
if($("#commentForm").validate()){
    console.log("true");
}else{
    console.log("false");
}
/**校验长度*/
$.validator.addMethod("checkUnameLen", function(value) {
if(/^[a-zA-Z0-9]{6,20}$/.test(value)){
return true;
}
return false;
}, "请输入6-20位字符,不包含汉字及特殊字符");
阅读 1.8k
1 个回答

你的验证方法错了,
是$("#commentForm").valid()

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题