Is there any way to restrict characters in ionic input type=text or number


i’m using ionic 2 there any possible way to restrict the input type to certain characters.

i know minlength or maxlangth attributes work but these are accepting any characters shows red lines in the bottom. i what that if my input type minlength=1 and maxlength =1 then text field take only one character.

There are two possible soultions that I can think of:


  public onKeyUp(event: any) {

    let newValue =;

    let regExp = new RegExp('^[A-Za-z0-9? ]+$');

    if (! regExp.test(newValue)) { = newValue.slice(0, -1);