I want to allow users to enter in the input field only numbers or fractional numbers, for this I use the regular

$(this).val($(this).val().replace(/[^\d.,]/g, "")); 

But there is a problem - you can enter multiple points / commas, how to regularly filter the input of more than one point or comma?

    1 answer 1

    Here are the regulars you need:

     [-+]?[0-9]*\.?[0-9]+ 

    [-+]? - Sign

    [0-9]*\.? - The integer part of a number with a period, if the number is a fraction.

    [0-9]+ - Either the fractional part or an integer.

    • I do not think how to sharpen your regular season for my needs, it is necessary that the entered second and subsequent dots / commas be replaced with emptiness as in my example - user193361 September