Home >Web Front-end >JS Tutorial >js onkeyup replace automatic replacement method

js onkeyup replace automatic replacement method

高洛峰
高洛峰Original
2017-03-12 11:38:341721browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn