Click to See Complete Forum and Search --> : form validation


dky1e
June 19th, 2002, 01:58 PM
Hi,

I have a set of text boxes and I want to test for the type of the input, whether it's a string, decimal or integer.

If any of those do not match I want to display an error message.

How to check the strings in text boxes if they satisfy the format?

How to display an alert window?

Thank you for your help!

vszilard
June 20th, 2002, 03:32 AM
1) There is a MessageBox Class in .net which provide you an alert window as customisable as you want.

ex.
MessageBox.Show("You must enter a name.", "Name Entry Error",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

Check the sdk documentation for mor information...

2) There is a Type Class in .net which provide you all the method you need to get a type to check a type...

GetType method..

Check the sdk documentation for mor information...

dky1e
June 20th, 2002, 07:57 AM
The problem with get type is that input to text boxes are strings.

V. Lorenzo
June 26th, 2002, 04:55 AM
Hi:

For doing validation stuff you may include the System.Text.RegularExpression namespace to your project and use the classes on it.

Take a look at http://windows.oreilly.com/news/csharp_0101.html.

You may also take a look at http://regexlib.com/Default.aspx., you will find there a lot of regular expressions.

VictorL

Arild Fines
June 26th, 2002, 12:09 PM
You could always just try converting them to your desired format:

try
{
myDecimal = Decimal.Parse( myTextBox.Text );
}
catch( FormatException ex )
{
MessageBox.Show( "You entered a bad number, stupid!", "Bleh!" );
}