Hi @Pratik Dhole,
In Outsystems You have inbuilt Trim() function to remove space from start & End of a string you can use that.
for remove double space between 2 words. you need to validate your input by using Regular expression. /\s\s+/g
function replaceDoubleSpaces(str) {
return str.replace(/\s\s+/g, " ");
}
Kind regards,
Sanjay Kushwah
Hi Sanjay,
Thank you for your response. The trim() method effectively removes leading and trailing spaces from strings. how to pass a regular expression or function to that variable?
You need to call JS node on onchange/Onblur event on input then replace value of original input field with function return value using JS.
Or simply you can make validation if string contains double spaces, then valid=false to input and show the error message.
Can you provide your OML file so I can fix it and return it to you? Alternatively, you can provide images of what you need, and I can give you a solution based on those.
you simply have to call two inbuilt funtions of outsystems, while assigning,
TrimmedText = Trim(InputText) //This Trim will remove spaces from Start and End.
CleanedText = Replace(TrimmedText, " ", " ") // Replace will remove double place and convert it to single space.
Hope this helps.
Thanks,
Adarsh Patel
Hi Adarsh,It is not working, There's an issue with the replace() method—it doesn't seem to remove double spaces between characters.
Hi @Pratik Dhole
have implemented the same and attaching the below snippet,
between test and hello there is double space which is replaced to 0 space as mentioned in expression and there is only single space between hello and hello so it doesn't replace.
@Adarsh ,
i'm thinking he means any number of consecutive spaces, not just exactly 2,
Hi @Pratik Dhole ,
Use this below JS in input onkeydown event. to restrict double space between the words.
const inputField = document.getElementById($parameters.WidgetId);
inputField.addEventListener('input', function(event)
{
let currentValue = event.target.value;
let cleanedValue = currentValue.replace(/\s{2,}/g, ' ');
event.target.value = cleanedValue;
});
Regards
Jaya Kumar S