js限制文本框?yàn)檎麛?shù)和貨幣的函數(shù)代碼
更新時間:2010年10月13日 21:06:26 投稿:mdxy-dxy
js限制文本框?yàn)檎麛?shù)和貨幣的函數(shù)代碼,方便一些數(shù)據(jù)庫字段的控制。
限制為整數(shù)
<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)"
您可能感興趣的文章:
- 數(shù)字金額千位分隔的Javascript
- 用javascript判斷輸入數(shù)據(jù)是否貨幣并自動添加¥符號的代碼
- JavaScript 動態(tài)將數(shù)字金額轉(zhuǎn)化為中文大寫金額
- js格式化貨幣數(shù)據(jù)實(shí)現(xiàn)代碼
- JS實(shí)現(xiàn)金額轉(zhuǎn)換(將輸入的阿拉伯?dāng)?shù)字)轉(zhuǎn)換成中文的實(shí)現(xiàn)代碼
- JS格式化數(shù)字金額用逗號隔開保留兩位小數(shù)
- js整數(shù)字符串轉(zhuǎn)換為金額類型數(shù)據(jù)(示例代碼)
- js金額數(shù)字格式化實(shí)現(xiàn)代碼(加減逗號處理)
- javascript將數(shù)字轉(zhuǎn)換整數(shù)金額大寫的方法
- js下將金額數(shù)字每三位一逗號分隔
- Javascript將數(shù)字轉(zhuǎn)化成為貨幣格式字符串
- Javascript將數(shù)值轉(zhuǎn)換為金額格式(分隔千分位和自動增加小數(shù)點(diǎn))
相關(guān)文章
javaScript checkbox 全選/反選及批量刪除
javaScript checkbox 全選/反選及批量刪除實(shí)現(xiàn)代碼,需要的朋友可以參考下。2010-04-04javascript之dhDataGrid Ver2.0.0代碼
javascript之dhDataGrid Ver2.0.0代碼...2007-07-07簽名框(Textarea)限制文字?jǐn)?shù)量并適時提示
僅用了一行代碼就實(shí)現(xiàn)了文本框的文字輸入數(shù)量限制,并適時給出提示,一般常見于發(fā)表評論、留言或簽名框等.2009-10-10