01.
<!DOCTYPE html>
02.
<html>
03.
<head>
04.
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=windows-874"
/> <title>Untitled Document</title>
05.
<script type=
"text/javascript"
src=
"jquery-1.4.4.min.js"
></script>
06.
<script type=
"text/javascript"
>
07.
function
format(input)
08.
{
var
num = input.value.replace(/\,/g,
''
);
09.
if
(!isNaN(num))
10.
{
11.
if
(num.indexOf(
'.'
) > -1)
12.
{
13.
num = num.split(
'.'
);
14.
num[0] = num[0].toString().split(
''
).reverse().join(
''
).replace(/(?=\d*\.?)(\d{3})/g,
'$1,'
).split(
''
).reverse().join (
''
).replace(/^[\,]/,
''
);
15.
if
(num[1].length > 2)
16.
{
17.
alert(
'You may only enter two decimals!'
);
18.
num[1] = num[1].substring(0,num[1].length-1);
19.
}
20.
input.value = num[0]+
'.'
+num[1];
21.
22.
}
23.
else
24.
{
25.
input.value = num.toString().split(
''
).reverse().join(
''
).replace(/(?=\d*\.?)(\d{3})/g,
'$1,'
).split(
''
).reverse().join(
''
).replace(/^[\,]/,
''
)
26.
};
27.
}
28.
else
29.
{
30.
alert(
'You may enter only numbers in this field!'
);
31.
input.value = input.value.substring(0,input.value.length-1);
32.
}
33.
34.
}
35.
36.
</script>
37.
38.
</head>
39.
40.
<body>
41.
<form>
42.
<input type=
"text"
onkeyup=
"format(this)"
onchange=
"format(this)"
onblur=
"if(this.value.indexOf('.')==-1)this.value=this.value+'.00'"
>
43.
</form>
44.
</body>
45.
</html>