cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Restricting Input Box to Accept Only Numeric Data in SAP Build Apps

Hossam_Fathy
Explorer
527

Hello,

I have created a Data Entity with a field where the data type is set to Number. Then, I created a Page Variable with the data type also set to Number.

I added an Input Box and bound it to the Page Variable. The data entered in the Input Box is supposed to be stored in the data entity field, which only accepts numeric values.

Issue:

Even though the data type is set to Number in both the Page Variable and the Data Entity field, the Input Box still allows the user to enter and save non-numeric values.

Question:

How can I restrict the Input Box to accept only numeric values and prevent the user from entering non-numeric characters?

Accepted Solutions (1)

Accepted Solutions (1)

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

The best I can find is to use the "Set Component Properties" flow function with the onChange event of the input field.

Dan_Wroblewski_0-1738662529200.png

You set the component's value field with the following formula:

IF(MATCHES_REGEX(SUBSTRING(pageVars.input,-1), "[0-9]"),pageVars.input,SUBSTRING(pageVars.input,0,-1))

 It checks for a digit at the end and if not it removes the character. The "input" variable is a text field -- you'll have to convert it when you want to use as a number.

I still get a small flash of the character and its removal, but it's pretty quick.

Our old friend @kleventcov (Kirill 😺) has a wonderful blog on validation schemes which are worth checking out. It includes validation on submit though not on individual field input: https://community.sap.com/t5/technology-blogs-by-sap/moderating-user-input-in-sap-build-apps/ba-p/13...

Answers (0)