2

我有两个输入字段:urlemail

我正在使用Vuelidate并且我想制作一个自定义验证器,用于检查 url 域名是否等于电子邮件域名。

有效示例:

网址:(https://)www.mydomain.example

电子邮件:johndoe@mydomain.example

无效示例:

网址:(https://)www.mydomain.example

电子邮件:johndoe@somedomaine.example

验证对象:

validations: {
    form: {
      url: { required, url, maxLength: maxLength(2083) },
      email: { required, email, maxLength: maxLength(255) },
      lastName: { required, maxLength: maxLength(100) },
      firstName: { required, maxLength: maxLength(100) }
    }
  },
4

1 回答 1

1

您可以使用如下custom validator调用matchUrl

  const matchUrl=(value, vm) => 
   value.substring(value.indexOf("@")+1) ===vm.url.substring(vm.url.indexOf(".")+1);

并将其用作:

validations: {
 form: {
  url: { required, url, maxLength: maxLength(2083) },
  email: { required,matchUrl, email, maxLength: maxLength(255) },
  lastName: { required, maxLength: maxLength(100) },
   firstName: { required, maxLength: maxLength(100) }
 }
},

检查这个工作示例

于 2018-10-07T17:07:25.243 回答