.NET Regular Expression for 24-hour Time Format

Can I get a regular expression in .NET that allows me to use only the 24 hour time format in the text box.

Thanks.

Best regards, MS

+3
source share
6 answers

Regular Expressions: Time hh: mm validation 24 hours format:

([0-1]\d|2[0-3]):([0-5]\d)

If you need seconds:

([0-1]\d|2[0-3]):([0-5]\d)(:([0-5]\d))?

Edit : To prevent AM / PM from ending, a partial match cannot be resolved or you need to put an expression between ^ and $.

^([0-1]\d|2[0-3]):([0-5]\d)(:([0-5]\d))?$
+9
source

try it

^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?$

This is a 24-hour time with extra seconds. (Source)

+4
source

DatePicker DateTimePicker , WPF Winforms? UE .

+3

Try

^([0-1]?\d|2[0-3])(:[0-5]\d){1,2}$
+1

, , , , datetime, :

  • . , , -, . , , ..
  • - 24
+1

I would advise you to take a look at The Regulator the next time you need a regular expression, this is a great tool for developing your expressions.

0
source

Source: https://habr.com/ru/post/1716553/


All Articles