【问题标题】:Vuelidate match / sameAs but ignore case sensitivity?Vuelidate匹配/sameAs但忽略大小写敏感?
【发布时间】:2021-01-27 17:14:08
【问题描述】:

我在表单上使用 vuelidate 并有两个输入“名字”和“姓氏”,然后在表单的另一部分是另一个输入,它结合了两个“名字姓氏”和必须匹配的是工作正常并验证。

我想要的是区分大小写无关紧要。所以只要字符串相等,大小写无关紧要,仍然会匹配和验证。有没有办法合并正则表达式?或者可能全部转换为小写?

  firstName: {
          required,
        },
  lastName: {
          required,
        },
  signature: {
        required,
        validSignature: (value, vm) => {
          const trimmedInput = value.trim().replace(/\s+/g, ' ')
          const first = vm.firstName
          const last = vm.lastName

          
          if (trimmedInput.toLowerCase() === 'signature on file') {
            return true
          }
         
          if (first == null || last == null) return false

          const expectedValue = first.concat(' ', last)

          return trimmedInput === expectedValue
        },
      },

【问题讨论】:

    标签: javascript vue.js vuelidate


    【解决方案1】:

    您可以使用正则表达式轻松实现这一点,或者只是在比较之前将字符串转换为小写/大写。

    例子:

    const upper = 'JOHN DOE';
    const lower = 'john doe';
    
    // Simple .toLowerCare() and compare
    console.log( upper.toLowerCase() === lower.toLowerCase() );
    
    // Reg Ex w/ Ignore Case
    const regex = new RegExp(lower, 'i');
    console.log( regex.test(upper) );

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-18
      • 2011-06-11
      • 1970-01-01
      • 1970-01-01
      • 2012-03-04
      • 2011-02-06
      • 2016-02-12
      相关资源
      最近更新 更多