标签: jquery-validate

jQuery Validate属性'max'在我的输入字段上不起作用

我有一个输入,我想将最大值设置为255.我不是提交表单,而是调用一个通过ajax提交数据的函数.

一些其他验证检查正在运行,如必需和数字,但max不起作用.我正在使用jQuery 1.4.4并验证1.7.

HTML

<input type="text" maxlength="3" style=" width: 190px" value="" name="Repeats" id="formfield_Repeats">
Run Code Online (Sandbox Code Playgroud)

JavaScript的

$(document).ready(function () {
   $("#my_form").validate({
      rules: {
         formfield_Repeats: {
            digits: true,
            required: true,
            max: 255
         }
      }
   });
});
Run Code Online (Sandbox Code Playgroud)

当我去保存应用程序时,我调用valid()表单上的方法.

它与jQuery和validate插件的版本不匹配吗?我可以升级两者,但项目很大,我不一定要重新测试整个应用程序.

jquery jquery-validate

0
推荐指数
1
解决办法
2792
查看次数

jQuery验证自定义消息不起作用

我无法获得适用于jQuery验证插件的自定义错误消息.我正在使用jQuery 1.7.2和jquery验证插件1.9.0.

我的表格很简单:

<form id="registrationform">
  <label for="rid">User Id</label><br/>
  <input id="rid" type="text" class="required"/><br/>
  <label for="remail">Email</label><br/>
  <input id="remail" type="text" class="required email"/>
</form>
Run Code Online (Sandbox Code Playgroud)

我的javascript很简单:

$(document).ready(function() {
    $("#registrationform").validate({
        rules: {
            rid : {
                required : true
            },
            remail: {
                required : true,
                email : true
            }
        },
        messages: {
            rid : {
                required : "id can not be empty"
            },
            remail: {
                required: "email can not be empty",
                email : "enter a valid email"
            }
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

jquery jquery-validate

0
推荐指数
1
解决办法
7114
查看次数

如何在没有http的情况下进行网址验证(或在验证通过后添加)?

我无法使自定义网址验证规则生效。

我要添加新规则:

 jQuery.validator.addMethod("complete_url", function(val, elem) {
// if no url, don't do anything
  return  /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/.test(val);
    });
 ...
 $("#new_website").validate({
    rules: {
          url: "complete_url",
         'website[url]': {
            url: true,
            required: true}
           }
        });
Run Code Online (Sandbox Code Playgroud)

但这让我回来

   invalid URL
Run Code Online (Sandbox Code Playgroud)

我检查了正则表达式在这里- http://www.rubular.com/。它正在工作,但是失败了我的自定义验证器。

我做错了什么?

url jquery-validate

0
推荐指数
1
解决办法
1万
查看次数

用于检查文本框值的jQuery Validation插件规则等于某些文本

我有一个文本框,我想检查用户输入的值是否等于"Jhon"或某个名称.我尝试使用EqualTo验证规则,但它不起作用.

$('#home').validate({
        rules: {            
          name: {
            required: true,
            equalTo: 'Jhon'
          },

           highlight: function(element) {
        $(element).closest('.control-group').removeClass('success').addClass('error');
          },
          success: function(element) {
            element
            .text('OK!').addClass('valid')
            .closest('.control-group').removeClass('error').addClass('success');
            }
      });

});
Run Code Online (Sandbox Code Playgroud)

jquery jquery-validate

0
推荐指数
1
解决办法
9055
查看次数

JQuery 验证 - 将规则分配为变量

我以以下格式指定规则

rules :{ 
col1: { 
required: true
},
col2: {
maxlength: 50
}
}
Run Code Online (Sandbox Code Playgroud)

这完全正常。是否可以将其分配给变量并将其添加到如下格式的规则中

var testRules = "{ col1: { required: true},col2: {maxlength: 50}}";

rules : testRules
Run Code Online (Sandbox Code Playgroud)

上面的代码不起作用,在 jquery 文件中出现异常。

如果可能的话,这样做。什么是正确的方法,或者我可以实现类似的目标吗?

谢谢

jquery jquery-validate

0
推荐指数
1
解决办法
3759
查看次数

jQuery验证IE7中不支持$ .validator.addClassRules()吗?

我在IE7中遇到以下脚本的一些问题:

$.validator.addClassRules({
   isemail: {
       email: true
   },
    required: {
        required: true
    }   
});
Run Code Online (Sandbox Code Playgroud)

这在IE8和其他浏览器中完美运行但是我在IE7中遇到以下错误:

Line: 158
Char: 3
Error: Expected ':'
Run Code Online (Sandbox Code Playgroud)

在我的代码中,这一行是:

isemail: {
Run Code Online (Sandbox Code Playgroud)

在jQuery validate插件站点(http://jqueryvalidation.org/jQuery.validator.addClassRules/)上没有提到缺少对此函数的支持,所以我在这里缺少什么?

我正在使用的jQuery版本是jQuery v1.10.2.我正在使用的jQuery验证版本是1.11.1.

任何帮助将不胜感激.

jquery jquery-validate internet-explorer-7

0
推荐指数
1
解决办法
3304
查看次数

允许整数和空格的Jquery规则验证

我当前接受整数的验证器是

$( "#UserForm" ).validate({
  rules: {
    contact: {
      required: true,
      number: true,
      minlength: 6,
    }
  }
});
Run Code Online (Sandbox Code Playgroud)

它工作正常

但现在我想改变它以便也接受空间.

我的代码应该是什么?请帮助我在jquery中初学者

jquery jquery-validate

0
推荐指数
1
解决办法
2719
查看次数

jQuery Validate Error Messages for Conditional Required and for Groups

I've been struggling trying to get custom error messages to display properly in 3 different situations when using the jQuery Validate Plug-in.

  • Where I have a Group and only 1 member of the Group is required.
  • Custom messages for check box fields.
  • Displaying an error message when a field is conditionally required.

I've made note of this post: How to show different error messages based on various conditions. Is it perhaps part of the solution to my issues? I've …

jquery jquery-validate

0
推荐指数
1
解决办法
5071
查看次数

无法在Angular应用程序中使用jQuery表单验证插件

我最近使用AngularJS将我的网站升级为单页面应用程序配置.从那以后我无法使用jQuery form validation plugin.我已经包含了所有需要的文件并检查了路径是否正确,但似乎是在浏览器中进行验证,而不是在我的代码中进行.

应用程序分为几个HTML文件,这些文件是动态注入的index.html.我包含所需文件的顺序是:

  • 所有CSS文件都加载在Head,然后是一些代码,包括<div ng-view></div>.
  • 然后我加载JS文件:jquery,jquery验证,jquery表单插件.

/*validate contact form */
$(function() {
    $('#contactForm').validate({
        rules: {
            inputName: {
                required: true,
                minlength: 2
            },
            inputEmail: {
                required: true,
                email: true
            },
            inputMessage: {
                required: true
            }
        },
        messages: {
            inputName: {
                required: "name needed!",
                minlength: "Your name must consist of at least 2 characters"
            },
            inputEmail: {
                required: "email needed!"
            },
            inputMessage: {
                required: "content required!"
            }
        },//submits the data …
Run Code Online (Sandbox Code Playgroud)

forms jquery jquery-validate angularjs

0
推荐指数
1
解决办法
7614
查看次数

复选框的 Jquery 验证错误消息位置

我正在使用jquery进行复选框验证(至少应该选中一个),这里我需要在所有复选框的末尾显示错误消息,但它总是显示在标签元素之后并将所有复选框移动到右侧,这看起来很奇怪. 下面是我的 html 代码:

           <div>
            <label>Please Select a color:</label> 
                <input type="checkbox" id="color"  name="color" value="red"> red</input>
                <input type="checkbox" id="color"  name="color" value="green"> green</input>
                <input type="checkbox" id="color" name="color" value="yellow"> yellow</input>
                <input type="checkbox" id="color"  name="color" value="black"> black</input>
           </div>
Run Code Online (Sandbox Code Playgroud)

谁能告诉我如何在不移动表单结构的情况下在所有复选框结束后在右侧显示错误消息。

提前致谢..

~亚什

jquery jquery-validate

0
推荐指数
1
解决办法
6344
查看次数