textbox should be date format
  • i Have one text box it should be date time formats like 12-12-2014  (the text box behavior should be date time picker)
    how to restrict the alphabets and controls
    the date time format of the text box is "dd-MM-yyyy" 
    if the user enter the date 32 or month 13  means it wont be allow 
    how can i write the code
  • 2 Comments sorted by
  • Vote Up0Vote Down WaqasWaqas
    172.00 Karma Accepted Answer
    You can use this code on TextBox_Validating Event.

     private void textBox2_Validating(object sender, CancelEventArgs e)
            {
                try
                {
                    DateTime Exp = Convert.ToDateTime(textBox2.Text);
                }
                catch
                {
                    MessageBox.Show("Please enter valid date.", "Validation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;
                    return;
                }
            }

  • thank u waqas its working

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Tagged

Popular Posts of the Week

    Optimum Creative