Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 159 characters in body
Source Link
JDB
  • 26.1k
  • 5
  • 81
  • 132

Check out the MaskedTextBox if you don't want to have to validate in the first place.

var l_control = new MaskedTextBox(); l_control.Mask = "00\:00"; 

If you want to make the first digit optional:

l_control.Mask = "90\:90"; 

Otherwise, you could use a regular expression. 4 digits separated by a colon would be: @"^\d{2}:\d{2}$". (The @ symbol prevents C# from treating '' as an escape character - nothing unique to regex.)

Check out the MaskedTextBox if you don't want to have to validate in the first place.

Otherwise, you could use a regular expression. 4 digits separated by a colon would be: @"^\d{2}:\d{2}$". (The @ symbol prevents C# from treating '' as an escape character - nothing unique to regex.)

Check out the MaskedTextBox if you don't want to have to validate in the first place.

var l_control = new MaskedTextBox(); l_control.Mask = "00\:00"; 

If you want to make the first digit optional:

l_control.Mask = "90\:90"; 

Otherwise, you could use a regular expression. 4 digits separated by a colon would be: @"^\d{2}:\d{2}$". (The @ symbol prevents C# from treating '' as an escape character - nothing unique to regex.)

Source Link
JDB
  • 26.1k
  • 5
  • 81
  • 132

Check out the MaskedTextBox if you don't want to have to validate in the first place.

Otherwise, you could use a regular expression. 4 digits separated by a colon would be: @"^\d{2}:\d{2}$". (The @ symbol prevents C# from treating '' as an escape character - nothing unique to regex.)