Displaying page
of
pages;
Items to
Title |
Test
Details
.Net Framework TimeSpan validation
|
Expression |
^\s*-?(\d{0,7}|10[0-5]\d{0,5}|106[0-6]\d{0,4}|1067[0-4]\d{0,3}|10675[0-1]\d{0,2}|((\d{0,7}|10[0-5]\d{0,5}|106[0-6]\d{0,4}|1067[0-4]\d{0,3}|10675[0-1]\d{0,2})\.)?([0-1]?[0-9]|2[0-3]):[0-5]?[0-9](:[0-5]?[0-9](\.\d{1,7})?)?)\s*$
|
Description |
Can be used to pre-validate strings before calling the TimeSpan.Parse() method in the .Net framework, to ensure that the string can be parsed without throwing an exception. The regex uses capturing groups instead of non-capturing groups so that it can easily be used as a pattern in XML Schema by simply removing the ^$ from the beginning/end.
This expression fully checks or enforces the [ws][-]{d|[d.]hh:mm[:ss[.ff]] }[ws] format as described in the MSDN help. It even checks the upper/lower boundaries on day values (10675199 days.)
|
Matches |
00:00:15 | 23:59:59 | 23:59:59.9999999 | -00:00:00 | 365 | -365 | 7.00:00:00.0000000 | 5:5:5 | 10:10 | 21:15 | 19:1 | 00:10 | 0 | 10675199.23:59:59.9999999 | -10675199.23:59:59.9999999 | 10599999 | 10669999 | 10674999 | 10675099
|
Non-Matches |
1.23:59:60 | 24:00 | 23:59:59.00000000 | 00:00:60 | 24:00:00 | 25:00:00 | 10675200 | 10676000 | 10680000 | 10700000 | 11000000
|
Author |
Rating:
Grim
|
Displaying page
of
pages;
Items to