Inserting/Removing Commas from Numbers

W/O Commas:
W/ Commas:
W/ Commas:
W/O Commas:

<SCRIPT>

function insert(form) {
     var re = /(-?\d+)(\d{3})/;    // -? means that it could be a negative
     var num = form.entry.value;

     // insert commas every 3 digits, 100535709 => 100,535,709
     while (re.
test(num)) { // while the test condition holds continue
          num = num.replace(re,"$1,$2"); 
          alert(num); // the alert msg is here to show you how the commas are inserted
     }
     form.commaOutput.value = num;
}

function remove(form) {
     var re = /,/g;

     form.plainOutput.value = form.commaInput.value.replace(re,"");
}

</SCRIPT>

<FORM>

W/O Commas: <INPUT TYPE="text" NAME="entry">
<INPUT
TYPE="button" VALUE="Insert commas" onClick="insert(this.form)">
W/ Commas: <INPUT TYPE="text" NAME="commaOutput">

W/ Commas: <INPUT TYPE="text" NAME="commaInput">
<INPUT
TYPE="button" VALUE="Remove commas" onClick="remove(this.form)">
W/O Commas: <INPUT TYPE="text" NAME="plainOutput">

</FORM>