How do I replace commas and line breaks with a blank space in a text field?

How could I replace commas ("," & ", ") with a space (" ") in simple text fields on blur?

The challenge is receiving a list of product ID's that are either in a list or comma separated, but I need to have them converted to be in-line with space separation.

(i.e. [ 4d55678, 43d1998... ] -to- [ 4d55678 43d1998... ]

I can live without the line breaks script, but I really need to replace the commas.

Anything that could help would be massively appreciated!


Jason Pelc


3 Answers

Voted Best Answer

Instead of using the On Blur event, consider using the Validate event. Here's a script that will work:

// Replaces each comma with a space
event.value = event.value.replace(/\,/g, " ");


By George Johnson   

… and for completeness sake, this would also take care of the line breaks as well:

event.value = event.value.replace(/[\,\r]/gm, " ") ;


Max Wyss   

You guys are truly experts at your craft. Thank so much!


Jason Pelc   


Please specify a reason: