vineri, 16 octombrie 2009

[C#][Regex] TimeStamp

I need a regex expression in order to validate a time stamp in the following template:
DDDD:HH:MM:SS.mmm
It contains:
- days (max 9999 -> 0 - 9999)
- hours (00-23)
- minutes (00-60)
- seconds (00-60)
- milliseconds (000-999)

To validate only digits it can be used:
@"\d{1,4}:\d{2}:\d{2}\.\d{3}"

To validate the hours/minutes/seconds it can be used:
(DDDD(0-9999):HH(00-23):MM(00-59):SS(00-59).mmm(000-999))
@"(\d{1,4}):([0-1]\d|2[0-3]):([0-5]\d):([0-5]\d)\.\d{3}"

to validate a timestamp in the following format it can be used the following regular expression: (HHHH(0-9999):MM(00-59):SS(00-59).mmm(000-999)):
@"(\d{1,4}):([0-5]\d):([0-5]\d)\.\d{3}"

Niciun comentariu:

Trimiteți un comentariu