ionChange not showing the expected behavior


#1

I have this ion-input here:

            <ion-input type="text" [(ngModel)]="info.date" (ionChange)="handleDate()" ></ion-input>

and I was trying to limit user entry to just numbers and “/” so I did this:

handleDate() {
    if (!/^[0-9/]+$/.test(this.info.date)) {
      this.info.date = this.info.date(0, this.info.date - 1);
    }
  }

Expected behavior : every time a user enters something other than numbers or “/” it doesn’t get displayed.

Actual behavior : the first invalid character gets erased as expected but the rest still shows up. For example,
if I enter ssss … the first s is handled successfully but the rest still shows up.


#2

Why not use a Pattern Validator:

var NUMBER_REGEXP = /^\s*(\-|\+)?(\d+|(\d*(\.\d*)))([eE][+-]?\d+)?\s*$/;

#3

Should the input be part of a form for the pattern validator to be used ? because I don’t use forms … I do old school validation.