码迷,mamicode.com
首页 > 其他好文 > 详细

只能输入数字

时间:2017-09-09 10:52:11      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:class   str   lan   bsp   数字   input   整数   限制   this   

http://m.jb51.net/article/83398.htm

第一: 限制只能是整数

<input type = "text" name= "number" id = number onkeyup= "if(! /^d+$/.test(this.value)){alert(‘只能整数‘);this.value=‘‘;}" />

第二: 限制是两位的小数

<input type = "text" name= "price" id = price onkeyup= "if( ! /^d*(?:.d{0,2})?$/.test(this.value)){alert(‘只能输入数字,小数点后只能保留两位‘);this.value=‘‘;}" />

 

只能输入数字

标签:class   str   lan   bsp   数字   input   整数   限制   this   

原文地址:http://www.cnblogs.com/hupan508/p/7497229.html

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