Script Categories

Forms >>> Commas.

Quickly add commas to any numerical form input. Great for displaying large numbers!

Input a Number:

Add the below code to the <body> section of your page:

<script language="javascript" type="text/javascript">
/* Visit for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
function commaSplit(srcNumber) {
var txtNumber = '' + srcNumber;
if (isNaN(txtNumber) || txtNumber == "") {
alert("Oops!  That does not appear to be a valid number.  Please try again.");;
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];
//  End -->
<form name="commas">
Input a Number:
<input type=text name="inpNumber" size=20 value="">
type=button value="Add Commas" onClick="document.commas.inpNumber.value=commaSplit(document.commas.inpNumber.value);">

JavaScript Editor Get Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.

Code was highlighted by 1st JavaScript Editor (The Best JavaScript Editor!).