<html>
<head>
<script>
function AutoCreatePoint(objectLocation){
var object_value=objectLocation.value;
var object_length=objectLocation.value.length;
if (!(object_value.match(/^\d+([.](\d+)?)?$/) || object_value.match(/^[.]\d+$/))){
return;
}
if(object_value!=""){
object_length=object_length-1;
var object_location=object_value.indexOf(".");
if(object_location==-1&&object_value!==""){
objectLocation.value=object_value+".00";
}else if(object_location==0){
objectLocation.value="0"+object_value;
}else if(object_location==object_length){
objectLocation.value=object_value+"00";
}
}
}function isChinese(input)
{
var isChinese=true;
for(var i=0;i<input.length;i++)
{
if(!(input.charCodeAt(i)>=0x4E00&&input.charCodeAt(i)<=0x9FFF))
{
isChinese=false;

}
return isChinese;
}
</script>
</head>
<body>
<form>
<input type="text" onchange="javascript:if(!isChinese(this.value)){AutoCreatePoint(this);}" />
</form>
</body>
</html>

解决方案 »

  1.   

    替换成这个函数,刚才的有点问题function AutoCreatePoint(objectLocation){
    var object_value=objectLocation.value;
    var object_length=objectLocation.value.length;
    if (!(object_value.match(/^\d+([.](\d+)?)?$/) || object_value.match(/^[.]\d+$/))){
    alert('false');
    return;
    }
    object_length=object_length-1;
    var object_location=object_value.indexOf(".");
    if(object_location==-1){
    // no decimal point
    objectLocation.value=object_value+".00";
    }else if(object_location==0){
    // the first is decimal point
    objectLocation.value="0"+object_value;
    }else if(object_location==object_length){
    // the last is decimal point
    objectLocation.value=object_value+"00";
    }else if (object_value.replace(/\d+[.]/, "").length < 2){
    // the middle is decimal point
    objectLocation.value=object_value+"0";
    }
    }
      

  2.   

    我把AotoCreatePoint改成AutoCreatePoint了应该没有问题吧,能够正确的补足尾数啊下面的内容就是对数字进行验证的。满足条件的格式有:
    连续的数字
    连续的数字+小数点
    连续的数字+小数点+连续的数字
    小数点+连续的数字var object_value=objectLocation.value;
    if (!(object_value.match(/^\d+([.](\d+)?)?$/) || object_value.match(/^[.]\d+$/))){
    alert('false');
    return;
    }