如何对formvalidation.io中的同一字段使用两个远程验证

时间:2018-03-10 13:51:19

标签: ajax remote-server formvalidation.io

我有一个登录表单,使用bootstrap表单验证。我想在电子邮件领域使用两个远程验证器。当我执行它时只使用第二个远程验证器。我怎样才能同时使用它们?

电子邮件验证

email: {
            verbose: false,
            validators: {
                notEmpty: {
                    message: 'The email address is required and cannot be empty'
                },
                regexp:{
                    regexp:/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i,
                    message:'This email address is not valid'
                },
                remote:{
                    type: 'POST',
                    url: 'ajax_check_email_exist.php',
                    data: function(validator) {
                            return {
                                email: $('[name="email"]').val(),
                        };
                    },
                    message: 'This email is not exist!',
                    delay: 1000,
                },
                remote:{
                    type: 'POST',
                    url: 'ajax_check_email_active.php',
                    data: function(validator) {
                            return {
                                email: $('[name="email"]').val(),
                        };
                    },
                    message: 'This email has not been activated yet!',
                    delay: 1000,
                }
            }
        }

1 个答案:

答案 0 :(得分:0)

为了拥有多个远程验证器,我做了以下操作。使用'别名'是关键。下面的示例包含验证器' mail_gun'这是一个远程验证器。

fields : {
  user_email: {
    selector: "#email",
    verbose: false,
    validators: {
      notEmpty: {
        message: 'Email is required'
      }, 
      emailAddress: {
        message: 'The input is not a valid email address'
      }, 
      mail_gun: {
        alias: 'remote',
        type: 'GET',
        url: 'https://api.mailgun.net/v2/address/validate?callback=?',
        crossDomain: true,
        name: 'address',
        data: {
          api_key: 'pubkey-samplekey'
        },
        dataType: 'jsonp',
        validKey: 'is_valid',
        message: 'We are unable to validate this email address'
      },
      remote: {
        url: '/guest/ValidateEmail',
        name: 'email',
        delay: 1000
      }
    }
  }
}