Regex allow digits and a single dot

后端 未结 5 728
难免孤独
难免孤独 2020-11-30 05:00

What would be the regex to allow digits and a dot? Regarding this \\D only allows digits, but it doesn\'t allow a dot, I need it to allow digits and

5条回答
  •  既然无缘
    2020-11-30 05:29

    \d*\.\d*
    

    Explanation:

    \d* - any number of digits

    \. - a dot

    \d* - more digits.

    This will match 123.456, .123, 123., but not 123

    If you want the dot to be optional, in most languages (don't know about jquery) you can use

    \d*\.?\d*
    

提交回复
热议问题