hi,
How can I restrict the value entered in the input box to only integers? not to enter a negative value or a decimal value in the input box
hi Rakesh
https://personal-wcnuuiyu.outsystemscloud.com/OutsystemBasic/maxlength?_ts=638518118051180802
this script is added on 'onkeypress' event on widget
if(event.charCode >= 48 && event.charCode <= 57 )
{
var val = document.getElementById($parameters.Inputvar).value;
var len = val.length;
if(len < $parameters.maxlength)
var newval = val + String.fromCharCode(event.charCode);
if(newval <= 100)
return true;
}
else
event.preventDefault();
event.preventDefault()
Please refer to attached OML file.
Hii, Rakesh M
I have used java script in onkeydown handler in input field.
if (event.key === 'e' || event.key === '+' || event.key === '-') { event.preventDefault();}
Folder name - word and screen name - integer
https://sunil-rajput.outsystemscloud.com/DailyTask/Integer?_ts=638518082196264188
Please refer to attached OML file
Hi Sunil,
The above implementation will allow decimal values where as the requirement was to allow only positive integers without a decimal.
Hi @Rakesh M ,
If you are not comfortable with JavaScript or regex, you can opt for the InputMaskReact forge component. With this, you can achieve formatting for whole numbers and specific formats like (99) 333-4555, and also restrict the maximum length.Please refer to attached OML file.
Hi @Rakesh M,
Please have a look at the attached OML and let me know if it helps.
Thanks,VP.
@Rakesh M
Add the restrictToWholeNumbers function to the onKeyPress event of the input field in the Properties panel.
Use the following JavaScript code in the client action to restrict input to whole numbers only
function restrictToWholeNumbers(event) {
const regex = /^[0-9\b]+$/; // Regex to match whole numbers and backspace
const key = event.key; // Get the pressed key
if (!regex.test(key)) {
event.preventDefault(); // Prevent input if not a digit or backspace
Hi Rakesh M ,
You can use regex pattern for whole number input box it will restrict other entries.
Thanks,
Narendra Tiwari