101
Views
13
Comments
Regex implementation for numeric values to be typed
Application Type
Reactive

For the Input I am adding validation that no non-numeric values are not allowed and only 1to 99 allowed and no -1,0,100 or any other values  like "e.-+" allowed . 

Text assigned with age having integer datatype 

I am using below expression on input change.


But Still I am able to type this values 

 I dont want it to be typed value more than 1 to 99 and other characters "-.e+"



Note: I dont want to use javascript or any other forge component Will it be possible

2023-12-11 08-54-13
Neha Agrawal
Champion

Hi Learner,

You can probably try using the following regex - "^[1-9][0-9]?$"

Note: This will allow only 1 to 99 as valid input.

Thanks,
Neha Agrawal

UserImage.jpg
Buddy_Outsystems

Hi Neha,


Thanks , for Answer.

I am already using "^(?:[1-9]|[1-9][0-9])$"

But It still allowing all , I want to restrict user from entering value > than 99, and these characters".-+eE".

It should not get typed.



2023-12-11 08-54-13
Neha Agrawal
Champion

Yes, the reason is the regex is used in OnChange event, where you can simply override the InputValue back to null when Regex_Search.Found is False.

Also, there is a HTML property named pattern ("[1-9][0-9]?"), you can try using that.
There is no other way to meet your requirements without JS.

Here is the full list of attributes that can be used.


Thanks,
Neha

UserImage.jpg
Buddy_Outsystems

I have override the InputValue back to null when Regex_Search.Found is False But It override the value If I add more than 99 that is 100 or greater but for e,.,-,+ and 0 It wont work

2025-02-21 07-07-34
Rishabh Tailor

Hi @New Learner ,

There are attributes you can give to the input, such as min and max and set their values to 0 and 99.

You cannot restrict  a user to type in a number more than 99 but with JavaScript you can add an event listener and replace the value with 99 when user types a value more than 99.


Check OML for reference. There is a screen named Input in mainflow.

   

Chat.oml
2024-12-10 04-40-04
Gitansh Anand

Hi @New Learner, please have a look at my component Restrict Characters, here is the link for demo.

Just type 0-9 in the first input of demo and then in the second input you can test it.

Please keep in mind that you will have to apply separate check for value less then 1 and grater then 99 because my component is only restricting the user from typing unwanted value.

One advantage is that it is complete client side logic so there is no server call.

Thanks
Gitansh Anand

2021-11-12 04-59-31
Manikandan Sambasivam

use the below regex

regex = /^(0?[1-9]|[1-9][0-9])$/; 

2024-06-08 15-17-54
Nawaz Khan

@New Learner I don't think you need regular expression here? I think this can be achieved simply with if condition. of course you can use the expression /[0-9]/g to only accept the numbers in input control on client side.

if age > 1 and age < 100 then proceed else return error message. 

2024-05-20 09-45-12
Jean Bastos

Agree with Nawaz, unless you have some requirement that did not know about it.

UserImage.jpg
Buddy_Outsystems
2024-07-16 17-36-51
Shradha Rawlani

Hello

Input mask forge component will helpful in this case

It have many properties for numeric and decimal also which will meet your requirements 

Regards

Shradha

UserImage.jpg
Buddy_Outsystems

I think they used Javascript. I dont want Javascript.

2024-06-08 15-17-54
Nawaz Khan

@New Learner you can use the if condition on either of sides (client, server). Regular expression should also be on either of sides

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