只能输入数字和小数点的正则

只能输入数字和小数点的正则

<input type="text" autocomplete="off" id="price" autofocus="autofocus" onkeyup="value=value.replace(/[^\d^\.]+/g,'')">

 

 onkeyup="value=value.replace(/[^\-?\d.]/g,'')"  仅允许输入:正负小数。 

 

<input type="text" autocomplete="off" id="price" autofocus="autofocus" onkeyup="value=value.replace(/[^\d^\.]+/g,'').replace('.','$#$').replace(/\./g,'').replace('$#$','.')"> 仅允许输入一个小数点。

 

posted on 2021-05-11 11:27  快乐鱼  阅读(3776)  评论(0编辑  收藏  举报

导航