【问题标题】:Email Validation using JQuery (emails matching) [closed]使用 JQuery 的电子邮件验证(电子邮件匹配)[关闭]
【发布时间】:2014-03-31 10:16:20
【问题描述】:

我在我的表单上使用以下验证,因为我有一个 email address 字段和 confirm email address 字段我需要一些验证以确保这两个字段匹配,我目前有以下内容,这给了我错误消息即使匹配也不匹配,有人知道为什么会这样吗?

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'
            },
     }

【问题讨论】:

  • 即使我的电子邮件匹配正确,它也会告诉我它们不匹配
  • 请创建一个 jsfiddle。
  • “entry[email]”是输入元素的id吗??
  • 对不起,伙计们,我的输入元素的 ID 不同,现在可以使用了!谢谢:)
  • 你为什么不跟进first version of your question?切勿重复发布!

标签: jquery jquery-validate


【解决方案1】:

试试这个方法

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

【讨论】:

    【解决方案2】:
    $('#email).validate({
      ...
      rules: {
        ...
        'entry[confirm_email]': {
          equalTo: "entry[email]"
        }
      }
    });
    

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

    【讨论】:

    • "这里entry[email]应该是输入元素的id!!" ~ 那不是真的!!只需要是一个有效的 jQuery 选择器。见:jsfiddle.net/6ux42
    猜你喜欢
    • 2018-07-30
    • 2011-08-12
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 2016-05-21
    • 2014-07-20
    • 1970-01-01
    相关资源
    最近更新 更多