<script
language="javascript"
type="text/javascript">
function
commaSplit(srcNumber)
{
var
txtNumber =
''
+
srcNumber;
if
(isNaN(txtNumber)
||
txtNumber ==
"")
{
alert("Oops!
That does not appear to be a valid number. Please try again.");
fieldName.select();
fieldName.focus();
}
else
{
var
rxSplit =
new
RegExp('([0-9])([0-9][0-9][0-9][,.])');
var
arrNumber =
txtNumber.split('.');
arrNumber[0]
+=
'.';
do
{
arrNumber[0]
=
arrNumber[0].replace(rxSplit,
'$1,$2');
}
while
(rxSplit.test(arrNumber[0]));
if
(arrNumber.length
>
1)
{
return
arrNumber.join('');
}
else
{
return
arrNumber[0].split('.')[0];
}
}
}
</script>
<form
name="commas">
Input a Number:
<input
type=text
name="inpNumber"
size=20
value="">
<input
type=button
value="Add
Commas"
onClick="document.commas.inpNumber.value=commaSplit(document.commas.inpNumber.value);">
</form>