I'm trying to make a regex to accept both integer and double values (positive and negative).
This is what I have:
@"-?d*(?:\d*\.\d*)?$"
Before this is marked as a duplicate question, with all the questions I've checked in SO I end up with the SAME PROBLEM:
5 and -5 -> true
5.00 and -5.00 -> true
BUT... 5. and -5. -> true
It takes < numbers + point only >, in this case ''5.'' and ''-5.'' as a "valid" numbers. Again, this very same problem was present in other similar answers I've already compiled.
This should works for you:
@"-?\d+(?:\.\d+)?"
Matchs only the dot only when have digits after it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With