Posted in Javascript onOctober 13, 2010
限制为整数
<html> <head> <script language="javascript" type="text/javascript"> var G=document.getElementById; function checkNumber(){ var reg = /^(?:0|[1-9][0-9]?|100)$/; var strNumber = G("txtNumber").value; alert(reg.test(strNumber)) } </script> </head> <body > <input type="text" value="" id="txtNumber" title="Please enter a number witch between 0 and 100 .."> <button onclick="checkNumber();">CheckNumber</button> </body> </html>
限制为货币
<script language="JavaScript" type="text/javascript"> <!-- function checkMoney(obj){ var tempValue=obj.value.replace(/(^\s+)|(\s+$)/g,''); if(!tempValue){return;} if(/^-?\d+(\.\d+)?$/.test(tempValue)){ obj.value=parseFloat(tempValue).toFixed(2); }else{ alert('请输入合法的货币值!'); obj.select(); return; } } //--> </script> onblur="checkMoney(this)"
js限制文本框为整数和货币的函数代码
- Author -
mdxy-dxy声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@