Home > Article > Web Front-end > js onkeyup replace automatic replacement method
This article introducesjs onkeyup replace automatic replacement method
function checkFloatNum(obj) { //先把非数字的都替换掉,除了数字和. obj.value = obj.value.replace(/[^\d.]/g,""); //必须保证第一个为数字而不是. obj.value = obj.value.replace(/^\./g,""); //保证只有出现一个.而没有多个. obj.value = obj.value.replace(/\.{2,}/g,"."); //保证.只出现一次,而不能出现两次以上 obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); }
The above is the detailed content of js onkeyup replace automatic replacement method. For more information, please follow other related articles on the PHP Chinese website!