Expand my Community achievements bar.

Function Trim

Avatar

Former Community Member
Hello:

I have realized a form with several fields that the user must refill, but I want to control that it cannot introduce spaces in target. I have seen that there are two methods Ltrim and Rtrim which work in FormCalc, but are not valid in JavaScript. The trim method for JS doesnt work either. Can someone kindly advise how to eliminate the spaces in target of the beginning or any method to obtain the same result as using trim?



Thanks for your answers
2 Replies

Avatar

Former Community Member
Is there a reason you don't want to use the FormCalc methods? JavaScript doesn't have a built in trim method.



Alternatively if you do a google search for JavaScript trim() there are a bunch of examples where people implemented their own trim() methods based on what JavaScript provides. Maybe you could make use of one of those.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
With javascript:



function RLTrim(Cadena){

var str = new String(Cadena);

return str.replace(/(^\s*)|(\s*$)/g,"");

}