[Vuejs]-Validating regex on vue.js input field keypress event

0👍

You can change pattern.test(e.target.value) to e.key.match(pattern)

validateLinuxPath() {
  let pattern = /^\/$|(\/[a-zA-Z_0-9-]+)+$/;
  let res = event.key.match(pattern);
  if (!res) {
    event.preventDefault();
    return false;
  }
}

Leave a comment