码迷,mamicode.com
首页 > 移动开发 > 详细

金额验证 适用手机端

时间:2015-12-02 18:23:02      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:

1 <input type="number" placeholder="1.00元" name="get_price" id="get_price" max="1000">

 


 1 $("#get_money").keyup(function(){
 2      var money = $("#get_money").val();
 3      var re = /^(-)?(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/ ;
 4      if(!re.test(money)){
 5 
 6         if(money.indexOf(".")==1 && money.length==2){
 7 
 8         }else if(money.length ==5){
 9             $(this).val(money.substr(0, 4));
10 
11         }else if(money.substr(0, 2)!=‘0.‘&& money.substr(0, 1)==0){
12 
13             $(this).val(money.substr(1, 2));
14 
15         }else if(money.length >3){
16 
17             $(this).val(parseFloat(money).toFixed(2));
18         }
19         
20      }
21   })

 



  

金额验证 适用手机端

标签:

原文地址:http://www.cnblogs.com/kellie/p/5013514.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!