0

I'm using vuelidate on a form and have two inputs "First Name" and "Last Name" then in another section of the form is another input that combines the two "first name last name" and the must match which is working fine and validates.

What I would like is for the case sensitivity to not matter. so as long as the strings are equal the casing does not matter and still will match and validate. Is there a way to incorporate a regular expression? or possible convert all to lowercase?

  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
        },
      },
hendy0817
  • 979
  • 2
  • 20
  • 47

1 Answers1

1

You can achieve this pretty easy with Regex or just simply converting your string to lower/upper case before the comparison.

Example:

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) );
mwilson
  • 12,295
  • 7
  • 55
  • 95