We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

IMMEDIATE HELP WANTED: Time values in TextBox

Hi.

I have a textbox which is to be entered time value in HH:mm format. It contains no of hours and mins.
eg-:
56:45[Fifty six hours and fourty five mins]

What is the best way to do..?
problem stop the entering invalid minutes.


1 Reply

AD Administrator Syncfusion Team April 8, 2008 10:47 AM UTC

Hi Apwickrama,

Thank you for your interest in Syncfusion Products.

To restrict the user to display valid time alone in the TextBoxExt, please refer the following code snippet for more details which performs the check when typing the Time and pressing Enter key:


private void textBoxExt1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
string str = this.textBoxExt1.Text;
int ind = str.IndexOf(":");
string hr = str.Substring(0, ind);
string min = str.Substring(ind + 1, 2);
int hour = Convert.ToInt32(hr);
int minutes = Convert.ToInt32(min);
if (hour > 23 || hour < 0 || minutes < 0 || minutes > 59)
{
MessageBox.Show("Invalid date and time");
this.textBoxExt1.Text = "";
}
else
{
MessageBox.Show("Valid Time");
}
}
}


Please let me know if any concerns.

Regards,
Fathima



Loader.
Live Chat Icon For mobile
Up arrow icon