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?
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.
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
can i use this in a table? cause i'm using my input widet in a table list
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?
the input field using an integer data type so there's no setting for the Max Length value in the properties
It worked. Thank you! ^^
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.
ThanksGitansh Anand