zoukankan      html  css  js  c++  java
  • vue input框数字后保留两位小数正则

    <el-input
    type="text"
    v-model.trim="ruleForm2.marketPrice"
    maxlength="10"
    @keyup.native="ruleForm2.marketPrice =ruleForm2.marketPrice = ruleForm2.marketPrice.replace(/[^d.]/g,'');
    ruleForm2.marketPrice = ruleForm2.marketPrice.replace(/.{2,}/g,'.');
    ruleForm2.marketPrice = ruleForm2.marketPrice.replace(/^./g,'');
    ruleForm2.marketPrice = ruleForm2.marketPrice.replace('.','$#$').replace(/./g,'').replace('$#$','.');
    ruleForm2.marketPrice = ruleForm2.marketPrice.replace(/^(-)*(d+).(dd).*$/,'$1$2.$3');
    "
    ></el-input>
     
     

    function clearNoNum(obj)

    {

    //先把非数字的都替换掉,除了数字和.

    obj.value = obj.value.replace(/[^d.]/g,"");

    //保证只有出现一个.而没有多个.

    obj.value = obj.value.replace(/.{2,}/g,".");

    //必须保证第一个为数字而不是.

    obj.value = obj.value.replace(/^./g,"");

    //保证.只出现一次,而不能出现两次以上

    obj.value = obj.value.replace(".","$#$").replace(/./g,"").replace("$#$",".");

    //只能输入两个小数

    obj.value = obj.value.replace(/^(-)*(d+).(dd).*$/,'$1$2.$3');

    }

  • 相关阅读:
    发送邮件程序
    T-SQL存储过程、游标
    GPS经纬度换算成XY坐标
    开博了
    你应该知道的 50 个 Python 单行代码
    想提升java知识的同学请进
    adb工具包使用方法
    红米note3刷安卓原生
    hadoop 使用和javaAPI
    django学习——url的name
  • 原文地址:https://www.cnblogs.com/lan-cheng/p/10723439.html
Copyright © 2011-2022 走看看