`
qq38450529
  • 浏览: 27130 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

只能输入浮点数

阅读更多
$(":text[number]").live("keyup",function(){
    //先把非数字的都替换掉,除了数字和.\d表示数字 \.表示点 而正则中的.表示出了回车和换行以外的字符.在这里正则将非数字和点的字符转为空
    this.value = this.value.replace(/[^\d\.]/g,"");
    //必须保证第一个为数字而不是.将
    this.value = this.value.replace(/^\./g,"");
    //去除所有的汉字
    this.value = this.value.replace(/[^\x00-\xff]*/g,"");
    //保证.只出现一次,而不能出现两次以上
    this.value = this.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
});

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics