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



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

电子邮件验证

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

我做了以下操作,以便拥有多个远程验证器。使用"别名"是关键。下面的示例具有验证器"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
      }
    }
  }
}

相关内容

  • 没有找到相关文章

最新更新