'Validate RegEx while typing

I have an input field and date schema that I need to validate (dd.mm.yy). I can not use a regular pattern for input, because it should not be allowed users to type letters, they need to type 22 and if the third one is not a dot, the type should be prevented.

The front is written in vue.js so I have

<input v-on:change="changeFunction" :sr-only="true" placeholder="dd.mm.yy"></input>

and then I tried to use functions like this

validate (e) {
      let number = new RegExp('(0[1-9]|[12][0-9]|3[01])[. /.](0[1-9]|1[012])[. /.]')
      let validate = number.test(e)
      if (validate) { return true }
}

and then to validate

changeFunction ({name, value}) {
      
      if (this.validate(value)) {
        do something
      } else {
        do something else
      }
    }

I get true and false once the type is complete, but I can type anything inside the input, not just numbers and dots. So is there any way that I can check RegExp while I am typing number by number and to prevent type if RegExp is not matched

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source