Text input validation only decimal no special char(, - )
Question
Application Type
Mobile

Hi,

I am working on the decimal validation in outsystems mobile and i have achieved below validation using imask lib.

- accept decimal

- prevent numbers upto two digit after decimal point

But there is an issue with '-' sign. I am not able to prevent this in the input field.

Here is my input field setting.

Also i am trying to prevent this by below JavaScript code but it failed.

if (event.key === 'e' || event.key === '+' || event.key === '-') {
    event.preventDefault();
}

Requirement : Only accept number and decimal in input field

Problem statement : Still accept "-" sign not able to prevent 

Hi Swapnil,

You need to explore more on Javascript side. May be you need to add inputmode='Numeric/decimal' CSS or any other JS based on Keyboard EVENT.

https://www.geeksforgeeks.org/how-to-force-input-field-to-enter-numbers-only-using-javascript/



Dileep

Hi Swapnil,

Use regex to validate decimal.


Hi Swapnil,

I attached a sample OML for your problem's description. Please verify.

URL : https://saravanan-gamechanger.outsystemscloud.com/PreviewInDevices/?IsMobilePreview=True&DeviceName=Smartphone&URL=/TEST_MOB/DECIMAL?_ts=637591015136760183

Regards,

Saravanan Santhanam

TESTMOBDECIMAL12062021.oml

Hi,

Thank you guys !

I tried below things because i need finish this task ASAP.

I took one more extra variable name Input2 and actual value store in Input1

OnKeyUp event i got the pressed key and through js i used in client action.

If that key is undefined then assign input1 = input2 if not then assign input2=input1

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