Copy link to clipboard
Copied
Hi, I need a quick JavaScript that will take a form field entery (say First_Name) and remove any whitespace or blanks that the end-user might have entered before and after whatever was typed.
Also, where to put that script in the field? There is already some validation going on that is working, but I'm uncertain is this would ba a custom "Action" or custom "Format".
Basically, I want whatever text the user types into the form field to be stripped of whitespace (except for spaces between say the first and middle name) and then left-justified
Thanks!
Copy link to clipboard
Copied
Hi,
In the validation tab, add this to your script
event.value = event.value.trim();
you could also assign it to a variable if you are doing more work on it
var trimmedString = event.value.trim();
// other code goes here
event.value = trimmedString
Copy link to clipboard
Copied
Yep. That did it. Thanks!
I'm going to start another thread regarding the clear form/reset for button I've implemented.
Copy link to clipboard
Copied
Note that this will not work if used in older versions of Acrobat or Reader.
To make it more backwards-compatible you can do it like this:
function trim(s) {
if (typeof s != "string") return s;
return s.replace(/^\s+/,"").replace(/\s+$/,"");
}
event.value = trim(event.value);
The trim function can be placed as a doc-level script, so you could use it in multiple locations without having to re-declare it each time.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now