在提交表单的时候用js正则来控制input value必须为数字

 1 function check_num(obj){
 2     var num = obj.value;
 3     var preg = /^\d+$/;    /**只能是数字**/
 4     var regvalue = num.match(preg); /**匹配指定值**/
 5     var str = num.replace(/^(\d)+/g,"");
 6     if(regvalue == null ){
 7         alert("价格只能为数字!");
 8         obj.value = num.substring(0,regvalue.indexOf(str));
 9     }      
10     
11 }
javascript Code

 

价格:

 

posted @ 2014-10-17 11:47  savey  阅读(138)  评论(0)    收藏  举报
savey:better life,do it best