I need a regex in .NET that represents a decimal number with up to 9 digits to the left of the decimal point and 1 or 0 digits to the right. What I have isn’t working.
Here is what I have:
@"^\d{0,9}[\.\d]{0,1}$"
What am I doing wrong? This regex is currently allowing 10 digits to the left of the decimal point and no digits to the right although it does accept strings like this –> 12.
Well you have a character class
[\.\d]and you are saying :please match one or zero of either a . or a digit.
What you really want to do however would be this :
This says from the start of the string match 0 to 9 digits (maybe you need to do this {1,9} because as it stands now an empty string will also match), followed by maybe a dot with a digit and then the end of the string.