I need to validate a textbox
input and can only allow decimal inputs like: X,XXX
(only one digit before decimal sign and a precision of 3).
I'm using C# and try this ^[0-9]+(\.[0-9]{1,2})?$
?
\d* - 0 or more digits (the decimal part);
The [0-9] expression is used to find any character between the brackets. The digits inside the brackets can be any numbers or span of numbers from 0 to 9. Tip: Use the [^0-9] expression to find any character that is NOT a digit.
To match any number from 0 to 9 we use \d in regex. It will match any single digit number from 0 to 9. \d means [0-9] or match any number from 0 to 9. Instead of writing 0123456789 the shorthand version is [0-9] where [] is used for character range.
^[0-9]([.,][0-9]{1,3})?$
It allows:
0 1 1.2 1.02 1.003 1.030 1,2 1,23 1,234
BUT NOT:
.1 ,1 12.1 12,1 1. 1, 1.2345 1,2345
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