<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN"> 
<head>
<title>测试</title>
<script type="text/javascript">function test() {
var v = document.getElementById("ss").value;
if (v.match(/^10$|^\d(\.\d+)?$/)) {
alert("符合!");
} else {
alert("不符合!");
};
}</script>
</head><body>
测试<input type="text" id="ss" onblur="test()" /></body></html>

解决方案 »

  1.   


    function isDouble(s){
    s = trim(s);
    var p = /^[-\+]?\d+(\.\d+)?$/;
    return p.test(s);
    }
      

  2.   

    function isDouble(s){
    s = trim(s);
    var p = /^[-\+]?\d+(\.\d+)?$/;
    return p.test(s);
    }
      

  3.   

    这样应该就行了,textname是你文本框的名字,如果用id的话你就用 getElementById("textId")就是.
    支持10.000000和正负号,呵呵function isDouble(){
        s = document.all.textname.value;
        var p = /^[-\+]?((\d(\.\d+))|(10(\.0+))|10|(\d))$/;
            if(!p.exec(s))
    {
      alert("not");
    }
    else
    {
      alert("yes");
    }

    }