Easy way to datatype validate TextBoxes

G

Guest

In a form I have a number of textboxes that is to receive different types of
data from the user. I can of course validate what has been typed in when the
user press the Ok button by parsing through the contents of the individual
textboxes. However, the .NET framework being so extensive, I was wondering if
there were not already some smart way of handling this validation rather than
having to program it by yourself.

A datatype property that could be set on the textbox or perhaps an object
that could parse and validate it according to datatype would come in handy.
E.g. if you had a date TextBox, it could check that a valid date had been
entered, or perhaps even preventing the user from enterering invalid data in
the first place.
For numbers it could be an enforced format with only so many digits allowed
and thousand dividers and decimal points automatically displayed as well as
any currency characters. I guess I am looking for something like the format
that can be assigned to cells in Excel.

There is a mention of format strings, but the purpose of these seems more to
be a handling or display of a string which is already given, rather than
validating an entry of data or even preventing something wrong from being
entered in the first place.

I hope anyone has some usuful suggestions. If not I can make some methods
myself that I can put in a class for reuse. But with this huge framework, one
would think that something so general was already included.


Best regards,

Frank M.
 
S

Sijin Joseph

You are right there is a better way, they are called Validator control
and implement IExtenderProvider so that you can specify the type of
validation that you need on your controls in design view, just ike you
specify the tooltips for toolTipProvider.

Here are some great articles and implementations of the same
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms03162004.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms04202004.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms05182004.asp

This has some good validator implementations as well as other cool stuff.
http://www.genghisgroup.com/

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top