C# – .net c# text box date with mask – setup

cdatetimeinputnet

I have a c# .net project and want an input text box for a date value. I want it to display a default value of mm/dd/yyyy and then allow users to enter valid dates.

I have tried using a masked text box but it doesn't like having the above format.

If i try and use //____ looks naff and so does 00/00/0000 and of course if you put in '0' like 03/11/2009 you get 3/11/29 because the 0's are deleted as part of the mask.

What is the best way to set up an input box like this, effectively with a mask, only allowing numbers, and validation (though at this point I am not so worried about that).

This seems so simple and isn't.

Best Answer

Try examining the the date in the OnChange event. Check the length of the text, adding / when appropriate.

Alternatively, see if the the DatePicker may be a better choice...

Related Topic