46
Views
7
Comments
Solved
limit the max length in the integer input by using a javascript regular expression

I have an input widget with data type integer. I want to limit the input data to only 5 characters by using a regular expression with JavaScript in onChange, how should I make it?

2023-11-20 06-53-17
Neha Rathore
Solution

you can use Regex_Search take this from manage dependencies from text

then onChange event drag this server action pass your integer value and the Pattern as "\d{1,5}" and then in the same variable add the Regex_Search pattern that will solve your issue.

Still not able to get let me know I will add the OML.

2023-11-20 06-53-17
Neha Rathore

Hi,

You can you this in JavaScript 

document.getElementById("Input_Title").addEventListener("input", function() {  Input_Title.value = Input_Title.value.slice(0, 5);});

Here Input_Text will be the Name of the input that you want put the JavaScript on.

Hope this helps

Thanks

UserImage.jpg
Soo Jin Park

can i use this in a table? cause i'm using my input widet in a table list

2023-11-20 06-53-17
Neha Rathore

In the table, that approach may not be effective. Consider using a different method, such as a forge component, or create a client action logic that can be utilized in the OnChange event. Additionally, why not limit the Max. Length of the input to 5?

UserImage.jpg
Soo Jin Park

the input field using an integer data type so there's no setting for the Max Length value in the properties

2023-11-20 06-53-17
Neha Rathore
Solution

you can use Regex_Search take this from manage dependencies from text

then onChange event drag this server action pass your integer value and the Pattern as "\d{1,5}" and then in the same variable add the Regex_Search pattern that will solve your issue.

Still not able to get let me know I will add the OML.

UserImage.jpg
Soo Jin Park
2024-12-10 04-40-04
Gitansh Anand

Hi @Soo Jin Park, I can see that you have already found a solution by using Regex Search action, but it is making a server call, please have a look at my component Restrict Characters, it works on client side using JS, here is the link to demo for the component.

Thanks
Gitansh Anand

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