52
Views
5
Comments
Solved
How to restrict decimal points in input box ?

How to restrict numbers after the decimal points in the input box ?


2024-05-14 06-52-28
Srigovindh-EONE
Solution

Hi karthi K ,

This was a demo link for  your reference: Click here


use this javascript 

document.getElementById($parameters.Inputid).addEventListener('input', function (e) {    let value = e.target.value;    if (value === '') return;       const regex = /^\d*\.?\d{0,2}$/;    if (!regex.test(value)) {        e.target.value = e.target.getAttribute('data-last-valid') || '';    } else {               e.target.setAttribute('data-last-valid', value);    }});


 Refer the OML. 

Decimal.oml
2020-05-07 18-53-00
Rui Barradas
 
MVP
Solution

Hello Karthi,

You can use an Input Mask to do that.

There are several Forge components that you can explore, for example, this one:

https://www.outsystems.com/forge/component-overview/7838/input-mask-react-o11


Kind regards,

Rui Barradas

2024-05-14 06-52-28
Srigovindh-EONE
Solution

Hi karthi K ,

This was a demo link for  your reference: Click here


use this javascript 

document.getElementById($parameters.Inputid).addEventListener('input', function (e) {    let value = e.target.value;    if (value === '') return;       const regex = /^\d*\.?\d{0,2}$/;    if (!regex.test(value)) {        e.target.value = e.target.getAttribute('data-last-valid') || '';    } else {               e.target.setAttribute('data-last-valid', value);    }});


 Refer the OML. 

Decimal.oml
2024-05-22 06-12-56
Vignesh Prakash

Hi  @karthi K

Good Day!!!

Can you please elaborate your requirement?
Do you want the input box to not have decimal values at all or do you want to restrict the number of digits after the decimal point?

Thanks,
Vignesh Prakash.

UserImage.jpg
karthi K

restrict the number after the decimal point? sir

2024-05-22 06-12-56
Vignesh Prakash

Thanks for the clarification @karthi K sir, The solution from @Srigovindh-EONE above should do the trick, Please try and let us know if you face any issue with the implementation.

Thanks,
Vignesh Prakash.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.