132
Views
9
Comments
How To Trim the space at the beginning and end
  1. Trim the space at the beginning and end after the user is no longer active in the input field, as well as the double spaces between words.
2023-12-16 19-57-03
Sanjay Kushwah

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

UserImage.jpg
Pratik Dhole

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?

2023-12-16 19-57-03
Sanjay Kushwah

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.



2024-10-07 06-43-19
Aanchal Sharma

Hi @Pratik Dhole,

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. 

2024-07-09 06-45-01
Adarsh

Hi @Pratik Dhole,


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

UserImage.jpg
Pratik Dhole

Hi Adarsh,
It is not working, There's an issue with the replace() method—it doesn't seem to remove double spaces between characters. 

2024-07-09 06-45-01
Adarsh

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.


2021-09-06 15-09-53
Dorine Boudry
 
MVP

@Adarsh ,

i'm thinking he means any number of consecutive spaces, not just exactly 2,



2023-02-27 14-18-56
Jaya Kumar S

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

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