How to make regex search action to limit input with integer data type to 5 characters, but working on the client section only?
Hi @Soo Jin Park
I've added a js code that will work for all the inputs on each row added a class on a input and selected all inputs.
// Select all input elements with the class 'restrictedInput' const restrictedInputs = document.querySelectorAll('.restrictedInput'); // Add event listeners to all selected input elements restrictedInputs.forEach(inputElement => { inputElement.addEventListener('input', function (event) { inputElement.value = inputElement.value.slice(0, 5); }); });
Sample
I hope this helpsThanksTousif Khan
Hi Soo,
regular expression \d{5} will only accept 5 numeric digits.
I can't explain clearly because I'm using a tablet.
Regards
Hello,You can do it easily via JsThere is already Solution marked for this check herehttps://www.outsystems.com/forums/discussion/65176/how-to-limit-the-input-with-number-type/I hope this helpsBest RegardsTousif Khan
Hi Tousif Khan,
i can't use the code from the link you referenced because my input field is in a table list so it doesn't work for me
Hi @Tousif Khan, this code solves my question. Thank you
Hi @Tousif Khan
The code you provided helped solve the limit of input to 5 characters, but I ran into another problem. The value stored in the variable does not match what is entered in the input field. For example, I enter the number 202, only 20 is stored in the variable. How do I solve this?
HelloIn that case you can use a JS// Select all input elements with the class 'restrictedInput'const restrictedInputs = document.querySelectorAll('.restrictedInput'); // Add event listeners to all selected input elementsrestrictedInputs.forEach(inputElement => { inputElement.addEventListener('input', function (event) { inputElement.value = inputElement.value.slice(0, 5); });// add a output parameter in your JS code and Assign the value$outputParam = inputElement.value;});After this assign the value back to your variable.ThanksTousif Khan
Hi @Soo Jin Park,
https://www.outsystems.com/forums/discussion/65176/how-to-limit-the-input-with-number-type/
please refer the above discussion.
Thanks,Vignesh Prakash.
@Soo Jin Park
Use the following JavaScript code in the client action to limit the input to 5 characters:
function limitToFiveCharacters(event) {
const regex = /^\d{0,5}$/; // Regex to match up to 5 digits
const value = event.target.value; // Get the current value of the input field
if (!regex.test(value)) {
event.preventDefault(); // Prevent input if more than 5 digits
}
Hi @Manikandan Sambasivam
Do I just need to use this code in my JavaScript widget or do I have to do any other configurations on the input field?