I need regex patterns for floating point numbers with optional % sign at the end like
12.32
12.32%
0.32
.32
.32%
arbitrary length of numbers on left and right of floating point numbers. I need this to validate input in asp.net mvc app
UPDATE:
forgot following combinations
12%
35
45%
This regex should do it for you...
\d*\.\d+%?
Which means... zero or more digits (\d*) followed by a period (escaped \.) followed by one or more digits (\d+) followed by an optional % (%?)
Update: match whole numbers
\d*\.?\d+%?

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