RegEx validation of decimal numbers with comma or dot

前端 未结 4 1524
离开以前
离开以前 2020-12-16 18:22

How to validate such number input with one RegEx. Strings are not allowed. Two decimal positions after dot or comma.

Example:

123.34
1.2

4条回答
  •  猫巷女王i
    2020-12-16 18:56

    Try this regex:

    /^(\d+(?:[\.\,]\d{2})?)$/
    

    If $1 exactly matches your input string then assume that it is validated.

提交回复
热议问题