How to restrict inputbox only for Integers

Is there any way I can configure the Numeric Textbox to accept only Integers?


3 Replies

BC Berly Christopher Syncfusion Team April 7, 2020 06:50 AM UTC

Hi Shreekumar, 

Greetings from Syncfusion support.  

We can restrict the decimals by setting the validateDecimalOnType as true and define decimals value as 0 which is help us to restrict the decimals while typing in the NumericTextBox component as mentioned below to achieve the requested requirement.  

[app.component.html] 
<ejs-numerictextbox format="#" value="10" validateDecimalOnType="true" decimals="0"></ejs-numerictextbox> 
 
We have prepared the sample and attached it below. 
 

To know more about NumericTextBox component, please refer the below documentation and demo link. 
 
 
 

Regards, 
Berly B.C


SH Shreekumar April 7, 2020 01:24 PM UTC

With this configuration, it is allowing decimal Point (.) also. Can it be restricted?


BC Berly Christopher Syncfusion Team April 8, 2020 08:03 AM UTC

Hi Shreekumar, 

We can restrict the decimal point in the NumericTextBox by finding the keycode for this and prevent the action for entering value in the keydown event as mentioned below.  

[app.component.html] 
<ejs-numerictextbox id="numeric" format="#" value="10" validateDecimalOnType="true" decimals="0" 
></ejs-numerictextbox> 
 
[app.component.ts] 
export class AppComponent { 
  constructor() { } 
  ngOnInit(){ 
    document.getElementById("numeric").addEventListener("keydown"function(args){ 
      if(args.keyCode === 190){ 
        args.preventDefault(); 
      } 
    }) 
  } 
} 
 
 
Please find the sample from the below link. 
 

Regards, 
Berly B.C

Loader.
Up arrow icon