Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JQuery进行电子邮件验证(电子邮件匹配)_Jquery_Jquery Validate - Fatal编程技术网

使用JQuery进行电子邮件验证(电子邮件匹配)

使用JQuery进行电子邮件验证(电子邮件匹配),jquery,jquery-validate,Jquery,Jquery Validate,我在我的表单上使用了以下验证,因为我有一个电子邮件地址字段和确认电子邮件地址字段。我需要一些验证以确保这两个字段匹配,我当前有以下字段,它给我错误消息,即使匹配,也不匹配,有人知道为什么会这样吗 rules: { 'entry[email]': { required: true, email: true }, 'entry[confirm_email]': {

我在我的表单上使用了以下验证,因为我有一个
电子邮件地址
字段和
确认电子邮件地址
字段。我需要一些验证以确保这两个字段匹配,我当前有以下字段,它给我错误消息,即使匹配,也不匹配,有人知道为什么会这样吗

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'
            },
     }
这样试试

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"
     }
 }


这里的“entry[email]”应该是输入元素的id

即使我的电子邮件匹配正确,它也会给我一条消息:它们不匹配。请创建一个JSFIDLE。输入元素的id是“entry[email]”吗?对不起,伙计们,我的坏消息是,我有一个不同的输入元素id,现在可以工作了!谢谢:)你为什么不跟我说?永远不要发布副本!“此处
entry[email]
应该是输入元素的
id
!!”~那不是真的!!它只需要是一个有效的jQuery选择器。见:
$('#email).validate({
  ...
  rules: {
    ...
    'entry[confirm_email]': {
      equalTo: "entry[email]"
    }
  }
});