Hola de nuevo.
He echo algunos cambios al código. Pruebalo a ver si funciona:
Código HTML:
<html>
<head>
<script>
function NumberFormat(num, numDec, decSep, thousandSep){
var arg;
var Dec;
Dec = Math.pow(10, numDec);
if (typeof(num) == 'undefined') return;
if (typeof(decSep) == 'undefined') decSep = ',';
if (typeof(thousandSep) == 'undefined') thousandSep = '.';
if (thousandSep == '.')
arg=/./g;
else
if (thousandSep == ',') arg=/,/g;
if (typeof(arg) != 'undefined') num = num.toString().replace(arg,'');
num = num.toString().replace(/,/g, '.');
if (isNaN(num)) num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num * Dec + 0.50000000001);
cents = num % Dec;
num = Math.floor(num/Dec).toString();
if (cents < (Dec / 10)) cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
num = num.substring(0, num.length - (4 * i + 3)) + thousandSep + num.substring(num.length - (4 * i + 3));
if (Dec == 1)
return (((sign)? '': '-') + num);
else
return (((sign)? '': '-') + num + decSep + cents);
}
function EvaluateText(cadena, obj,e){
opc = false;
tecla=(document.all) ? e.keyCode : e.which;
if (cadena == "%d")
if (tecla > 47 && tecla < 58)
opc = true;
if (cadena == "%f"){
if (tecla > 47 && tecla < 58)
opc = true;
if (obj.value.search("[.*]") == -1 && obj.value.length != 0)
if (tecla == 46)
opc = true;
}
if(opc == false)
return false;
}
</script>
</head>
<body>
<form name="frm">
numero
<input type="text" name="input1" size="15" value="500034567" onkeypress="return EvaluateText('%f', this,event);" onBlur="this.value = NumberFormat(this.value, '2', '.', ',')"><br><br>
</form>
</body>
</html>
Saludos,