- <!--
- 胡開明
- 用正則表達式控制價格輸入
- -->
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>用正則表達式控制價格輸入</title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <script type="text/javascript">
- var record={
- num:""
- }
- var checkDecimal=function(n){
- var decimalReg=/^/d{0,8}/.{0,1}(/d{1,2})?$/;//var decimalReg=/^[-/+]?/d{0,8}/.{0,1}(/d{1,2})?$/;
- if(n.value!=""&&decimalReg.test(n.value)){
- record.num=n.value;
- }else{
- if(n.value!=""){
- n.value=record.num;
- }
- }
- }
- </script>
- </head>
- <body>
- <h3>實用技巧:用正則表達式控制價格輸入</h3>
- 銷售價<input maxlength="10" size="18" type="text" name="price" value="" onkeyup='checkDecimal(this)'/>
- </body>
- </html>
新聞熱點
疑難解答