Ionic Input type number not work with dot


Dear all ,
I am newbie with ionic
now i got a problem when i try to use input type number ,
and i want to manage on dot just one dot , but number not store dot ,
it just store the value number, so i can’t manage it by value
anyone can help me?


Use an <ion-input> and a Validators.pattern().



thanks for reply , yes i did following ur link but it still not work , when i use pattern like “Validators.pattern(/^\d+.\d{2}$/)” but i still can input double dot . do you have any solution?


Change the ‘2’ to a ‘1’ -> Validators.pattern(/^\d+.\d{1}$/)


here is HTML Code

Number and here is Ts this.credentialsForm ={ number: [ '', Validators.compose([ Validators.pattern('/^\d+.\d{1}$/'), Validators.required ]) ] });

please help me check it what wrong?

const MY_REGEXP = /^\d+.\d{1}$/;





i still can input many dot


Its a validator, if you want to restrict the keys that can be entered, try:


<ion-input (keyup)="onKeyUp($event)" ... >


  const MY_REGEXP = /^\d+.\d{1}$/;

  public onKeyUp(event: any) {

    let newValue =;
    let regExp = new RegExp(MY_REGEXP);

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


Do you find use of keyup like that to be robust across platforms? I think it’s probably safer to let the form validator throw an error. But maybe that’s too paranoid.


I agree, that’s why I shared this link:


yes i want to restrict on keys but now i try it follow u , but when i put value it show nothing , note : i used type : “Number”


Try page.html:

<ion-input (keyup)="onKeyUp($event)" type="text" ... >

And page.ts:

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


  public onKeyUp(event: any) {

    let newValue =;
    let regExp = new RegExp(NUMBER_REGEXP);

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



How about this regex:


Thank Gizmo, i want to restrict on key , when i used type = “Number” so the key will be show just number and dot , but when i try to get target value from variable , it will not store dot , it just store number and also not return key code for me , so i don’t know how to restrict on dot , when user input .


This is a bad goal to have, in my opinion. There is no way to ensure it will work with all platforms. If you only need it on one platform, there is no need for Ionic. If you’re using Ionic, your goals should be on platform-independent behavior. Program for the browser, not for native functionality. The form validator is the way to go.


yes thanks you, @AaronSterling but i need to restrict the key this is user requirement, they don’t need to show expection while they miss input and edit it , they want us develop it like window base application that it will show nothing when they put wrong key and any exception!!!.


you could try text-mask which allows you to restrict what is typed. You’ll need to use the type=“tel” for the proper keyboard.
The site specifically says it doesn’t work with Ionic but there is a version that does.