Limit number of characters in input type number

后端 未结 13 1710
逝去的感伤
逝去的感伤 2020-12-18 08:08

Im trying to limit to X number the characters in a input (type of number). ive tried a lot of options and none seems to work. I dont want to use the option tel as it needs t

13条回答
  •  情歌与酒
    2020-12-18 08:32

    For Decimal values, lets say "25.2" code is as under.

    if(thisObj.value.indexOf(".") >=0)
    {
        if(fieldLength <= 4)
        {
            return true;
        }
        else
        {
            var str = thisObj.value;
            str = str.substring(0, str.length - 1);
            thisObj.value = str;
        }
    }
    else
    {
        if(fieldLength <= 2)
        {
            return true;
        }
        else
        {
            var str = thisObj.value;
            str = str.substring(0, str.length - 1);
            thisObj.value = str;
        }
    }
    

提交回复
热议问题