allowing input only for float number

后端 未结 7 505
别那么骄傲
别那么骄傲 2020-12-09 21:58

I have pain-time when making input that only allows float number with jquery library. my code can\'t prevent chacacter \".\" when it\'s becoming first input, can anyone guid

相关标签:
7条回答
  • 2020-12-09 23:00

    This works for me:

    var str = document.getElementById('product_'+id_product).value;
    if( !str.match(/^[0-9]*([.,][0-9]+)?$/) ) {
     console.log("Value must be a number or float number");
    }else{
     console.log("The number is valid");
    }
    

    I hope this can help someone. Regards!

    0 讨论(0)
提交回复
热议问题