Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Preventing commas in text fields.

Avatar

Level 1

I have created a form in which a text field requires the user to enter detailed documentation. In doing so, the user tends to use a comma within the description. As the data within the form is extracted to Excel I can not allow commas. Can anyone tell me what java script would be needed to resolve this issue or if it is possible? I am also open to other suggestions such as knowing how to make the forms extract as pipe delimited vs comma delimited.

Thank you

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

I'm not sure about the import into Excel with commas in the text, fixing that sounds like it would be the best solution.  But to stop someone from entering a comma character add the following JavaScript into the change event of the text field;

xfa.event.change = xfa.event.change.replace(/,/g,"");

This uses a RegEx (the bit between the "/" characters) to replace all occurances (because of the "g") with an empty string (the second parameter to the replace method).

Regards

Bruce

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi,

I'm not sure about the import into Excel with commas in the text, fixing that sounds like it would be the best solution.  But to stop someone from entering a comma character add the following JavaScript into the change event of the text field;

xfa.event.change = xfa.event.change.replace(/,/g,"");

This uses a RegEx (the bit between the "/" characters) to replace all occurances (because of the "g") with an empty string (the second parameter to the replace method).

Regards

Bruce