function keyPressInt(src){
var e=window.event;
code=e.keyCode;
if(code >=48 && code <=57)  return true;
else  {window.event.keyCode=null;return false;}
}
function keyPressFlt(src){
var e=window.event;
code=e.keyCode;
if(code >=48 && code <=57) return true;
else if(code == 46 && src.value.indexOf('.')==-1) return true;
else{  window.event.keyCode=null; return false; }
}
第一个输入整数
第二个输入浮点数
调用方法:
<input type="text" onKeyPress="keyPressInt(this)".....

解决方案 »

  1.   

    ptn=/[\d]{0,}[\.]{0,1}[\d]{0,}/;
    ptn.test(你的字符串)

    ptn.exec(你的字符串
    )
      

  2.   

    Expression:  ^\s*-?((\d{1,3}(\.(\d){3})*)|\d*)(,\d{1,2})?\s?(\u20AC)?\s*$
        
    Description:  Matches euro currency (portuguese regional options). Uses the dot sign as the thousands separator (optional) and the comma sign as the decimal separator. Matches only 2 digitals after decimal. Also matches negative numbers.  
    Matches:  [-123123,12 €], [12312432134], [-12.234.123,23]  [ More Details]  
    Non-Matches:  [1234.12,234]  
    http://www.regexlib.com:好多正则表达式。