2014-03-31 167 views
-4

我在窗体上使用以下验证,因为我有email address字段和confirm email address字段我需要一些验证以确保这两个字段匹配,我目前有以下内容我错误信息,即使它不匹配,任何人都知道这可能是为什么?电子邮件验证使用JQuery(电子邮件匹配)

rules: { 
      'entry[email]': { 
       required: true, 
       email: true 
      }, 
      'entry[confirm_email]': { 
      // required: true, 
       equalTo: "entry[email]" 
      }, 
}, 
     messages: { 
      'entry[email]': { 
       required: ' Please enter a valid email address', 
       minlength: 'Not a valid email address' 
      }, 
      'entry[confirm_email]': { 
       required: ' Please make sure email matches above', 
       minlength: 'Does not match above email address' 
      }, 
    } 
+0

什么是错误? –

+0

即使我的电子邮件正确匹配它给我的消息,他们不 –

+0

请创建一个jsfiddle。 –

回答

2

尝试这种方式

rules:{ 
    pwd:{ 
     required:true //First email section 
    }, 
    pwd1:{ 
     required:true,//Second email section 
     equalTo: "#same" //Use id of the first email text box here 
     } 
    }, 
messages:{ 
    pwd1:{ 
     equalTo: "Must be same as above email" 
    } 
} 

Working Example

0
$('#email).validate({ 
    ... 
    rules: { 
    ... 
    'entry[confirm_email]': { 
     equalTo: "entry[email]" 
    } 
    } 
}); 

这里 “进入[邮件]” 应该是输入元素的ID!

+0

_“这里'entry [email]'应该是输入元素的'id' !!”_〜**这不是真的!! **它只需要是一个有效的jQuery选择器。请参阅:http://jsfiddle.net/6ux42/ – Sparky