[Vuejs]-Custom numberfield does not validate against NaN

0👍

I see two mistakes in your code:

  1. You forgot to specify that the pattern is a regex
  2. Your regex will basically match anything

I corrected the regex and added the correct javascript object:

data: function() {
    return {
      number: 12345,
      pattern: new RegExp("^\d+$")
    };
  },

Codesandbox doesn’t let us escape \d, so you can test with [0-9]+ instead of \d in codesandbox.

I don’t know what input you want to allow exactly, but you can elaborate your regex using regex101.

Leave a comment