0

Regular expression with number and dot only

I use ^[0-9]*$ regular expression for number only. It works fine but now I need regular expression for number and dot only like user enter 4000.92 etc. Please help.

21st Mar 2017, 11:54 AM
Salman Mushtaq
Salman Mushtaq - avatar
4 Respuestas
+ 1
Hi Salman, maybe ^[0-9]*\.[0-9]*$ or ^[0-9]+\.[0-9]*$ if you want to be sure that the result stats with a number and not with a dot. Bye!
21st Mar 2017, 12:00 PM
Xavier Alonso
Xavier Alonso - avatar
+ 1
Hi Salman, I'm not sure what are you asking for. If you want only to accept the number.number format you could use ^[0-9]+\.[0-9]+$, but if you want to match with number.number o number (without decimals) formats you could use ^[0-9]+(\.[0-9]+)?$
21st Mar 2017, 2:03 PM
Xavier Alonso
Xavier Alonso - avatar
0
Xavier, this works thank you. Just one more question these regular expression needs . (decimal) required like I cannot enter 45 it accept 45.0. How to make this dot optional means it accept 45 also 45.00 but not other except (0-9 and .) Thank you.
21st Mar 2017, 1:08 PM
Salman Mushtaq
Salman Mushtaq - avatar
0
Xavier Alonso, thank you. Its work with ^[0-9]+(\.[0-9]+)?$
23rd Mar 2017, 1:02 PM
Salman Mushtaq
Salman Mushtaq - avatar