Di niente… prova anche questa, è più semplice e non mette i punti sulle migliaia…
codice:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Esempio</title>
<script type="text/javascript">
function numbersOnly(oMyField1, oKeyEvent) {
var nChar = (oKeyEvent || window.event || { charCode: 0 }).charCode, sChar = String.fromCharCode(nChar), rSeparator = /,/;
return nChar === 0 || /\d/.test(sChar) || (rSeparator.test(sChar) && !rSeparator.test(oMyField1.value));
}
function formatNumber(oMyField2) {
oMyField2.value = parseFloat(oMyField2.value.replace(",",".")).toFixed(2).replace(".",",");
}
function unformatNumber(oMyField3) {
oMyField3.value = oMyField3.value.replace(/,00|(,\d)0/g, "$1");
}
</script>
</head>
<body>
<form name="myForm">
Inserire importo: <input type="text" name="importo" value="5000,00" onblur="formatNumber(this);" onfocus="unformatNumber(this);" onkeypress="return numbersOnly(this, event)"; onpaste="return false;" /></p>
</form>
</body>
</html>