Hi,
Can I please have a regular expression in .NET, which will allow only 24 hr time format in the textbox.
Thanks.
Best Regards, MS
Hi,
Can I please have a regular expression in .NET, which will allow only 24 hr time format in the textbox.
Thanks.
Best Regards, MS
Regular Expressions: Time hh:mm validation 24 hours format:
([0-1]\d|2[0-3]):([0-5]\d)
If you need seconds too:
([0-1]\d|2[0-3]):([0-5]\d)(:([0-5]\d))?
Edit: To prevent trailing AM/PM, partial match can't be allowed or you have to put the expression between ^ and $.
^([0-1]\d|2[0-3]):([0-5]\d)(:([0-5]\d))?$
What about using DatePicker
or DateTimePicker
depending upon if you're using WPF or Winforms? This might be a better UE anyways.
I would suggest you take a look at The Regulator for next time when you need a regular expression, its a great tool for designing your expressions.
Personally, rather than go the validation route I would use a control like a datetime picker for the following reasons: