Regular expressions are the worst choice when it comes to validate dates and times (XML documents, also). But anyway, that is just a piece of advice.
Regarding your question, that does not make any sense, from a regular expression point of view.
You made it a complete line (symbols
^
&
$
at start & end). So how do you expect anything more in it?
If there are some other elements that should be validated, then put them in your regular expression.
If not, then expression will not match, which is basically its purpose :)
I corrected it a little bit:
Original:
Regex expressionToValidate_String_Structure = new Regex("^\\d{1,2}([.]\\d{1})$");
Modified
Regex expressionToValidate_String_Structure = new Regex(@"^\d{1,2}(?:.\d{1})?$");
- The
@
is here to avoid having to escape backslashes. This way, you can copy/paste directly from a regular expression editor.
- I made the decimal part a non capturing group (?: ... ), and gave it the
?
(zero or one) repetition.
- Stripped blockquotes from the
.
(any character) class (they were not needed).
But, once again using a regular expression to validate values from 0 to 59.9 is a bad choice; the one you actually have does not validate numbers from 0 to 59.9. It validates numbers from 0 to 99.9.
There is a tool,
Expresso[
^], which is really useful when you want to build and test complex regular expressions. I encourage you to use it for your specific issue.
[Edit: Matt T Heffron: corrected the Modified Regex]
Regex expressionToValidate_String_Structure = new Regex(@"^\d{1,2}(?:\.\d)?$");
You stripped the blockquotes from the
.
erroneously. That was the decimal point, not the (any character) class. Just escaping it with backslash is sufficient.
Also, you missed removing the unnecessary
{1}
quantifier from the digit in the fractional part.
\d
means exactly one
unless quantified. ;)