I have the following javascript:
str = item.value;
var pattern1 = /, /g;
var pattern2 = /,/g;
str = str.replace(pattern1, ",");
str = str.replace(pattern2, ", ");
item.value = str;
The problem is... each replace works, but not together.
The code works on a textarea and automatically ads a space after a comma, but catches if the users presses space after they type comma.
So it would replace:
", " to ", "
and
"," to ", "
Any help??
Thanks!!
Adam
str = item.value;
var pattern1 = /, /g;
var pattern2 = /,/g;
str = str.replace(pattern1, ",");
str = str.replace(pattern2, ", ");
item.value = str;
The problem is... each replace works, but not together.
The code works on a textarea and automatically ads a space after a comma, but catches if the users presses space after they type comma.
So it would replace:
", " to ", "
and
"," to ", "
Any help??
Thanks!!
Adam