JQuery验证比较字段的规则

时间:2011-12-14 15:42:53

标签: jquery jquery-validate

如何使用jquery validate.js添加规则来比较两个文本框值...?,

对于必填字段,我使用类似

的内容
   <script>
         $(document).ready(function () {
             $('[id$=txtname]').rules("add", {
                 required: true,
                 messages: {
                     required: "fill this"
                 }
             });
         });
     </script>

3 个答案:

答案 0 :(得分:2)

$('[id$=txtname]').rules("add", {
             required: true,
             messages: {
                 required: "fill this"
             }
});
//for the textbox you want to compare with 
$('[id$=txtname2]').rules("add", {
             equalTo: '#txtname',
             messages: {
                 required: "values not does not match."
             }
});

答案 1 :(得分:1)

$('#<%= Email.ClientID %>').rules('add', {
    required: true,
    email: true
});
$('#<%= EmailConfirm.ClientID %>').rules('add', {
    equalTo: '#<%= Email.ClientID %>',
    messages: {
        required: 'adeda',
        equalTo: 'olá mundo'
    }
});

答案 2 :(得分:0)

尝试使用equalTo方法

rules: { 
    TextBox1: 'required', 
    Textbox2: { 
        equalTo: '#Textbox1' 
    } 
}