I have a textbox inside of an asp:repeater. The textbox is used for an ordering system, and I want to restrict the user to only inputting up to 3 numbers before, and 2 numbers after a decimal. The decimal will be optional, and the user should be able to put X, XX, XXX, X.xx, XX.xx, XXX.xx, or any other combination of numbers, so long as it does not exceed the limit.
I am new to regex. Is regex the best way to accomplish this? If so, how?
You should probably search for a regex tutorial yourself before asking here, but the regex you want is ^\d{1,3}(?:\.\d{1,2})?$
^
Anchor to the start of the string\d{1,3}
Match 1-3 digits(?: )?
optional group
\.
Match a literal .
\d{1,2}
Match 1-2 digits$
Anchor to the end of the string