skip to content »

tenpoint.ru

Validating date in textbox in asp net

validating date in textbox in asp net-67

I wanted the complete text existing in the control to be selected at such time as the user enters the control. Clone the VS2010 project if you want to see the complete code. If you succeed, hit me up with a pull request – I will happily merge your changes.Unfortunately, there is apparently a bug in the implementation of the Masked Text Box control which prevents this from happening using the familiar as described here provided the solution for the moment.

Also, I may decide to extract this method out into its own class (Date String Formatter? First off, directly, and the user is entering text.Most importantly, I have set the mask and the prompt character to the standard format, using private constants.The mask format 00/00/0000 requires integers where the zero placeholders are, and ignores non-integer entries. This is set to true immediately after the mask is set in the constructor.The validator mainly checks the format of the provided value. If you'd like only to accept inputs in specified format you can set the Page Culture property manually. In case of Date type it also checks the range (e.g. I like this feature, especially that I've already seen a quite complex custom validator written to do exact this task. The same date "" will be validated differently for UK and US Cultures (in UK "DD. The trick here is that some people may enter 1/1/2012, others may enter 01/01/2012, and still others may try to use 1-1-12.

In my mind, all of these should resolve to the same date.

If any of these undesirable characters are found, we make a quick call to our Correct Date Text method, and straighten things out on the fly, so to speak.

Next, we want to perform a check when the user navigates away from the control, to be sure that what they have entered is, in fact, a valid date, as well as to perform any additional re-formatting required. The So, the thing which was driving me crazy about this control (and the Masked Text Box from which it derives) was that there did NOT seem to be a way to cause the text in the control to be selected upon entry, such as when an invalid string was entered, and the user is returned to the control to fix it. There are some limitations resulting from the need to get it done NOW which some design improvements would correct. You can find the source code for this at my Github repo.

For the purposes of my project, I have achieved these requirements.

The control has flaws to this point, in terms of general use (limiting the acceptable centuries comes immediately to mind), but it is a starting point.

Managing date information within the framework (or any framework, really . Please feel free to fork, and if you make happy improvements, hit me with a pull request. Do we really want to require some date, if we don’t know the correct birthdate? Folks who are good, tab through fields, and enter data. Not to mention the temptation to stop the tab-type-tab workflow by making you pick from a popup calendar. MS seems to have tossed this aside, and delivered the lame control we have at our disposal in the . There are probably reasons for this, but I don’t know what they are.