-
form validation
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!
-
alert windows
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...
-
The problem with get type is that input to text boxes are strings.
-
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
-
You could always just try converting them to your desired format:
Code:
try
{
myDecimal = Decimal.Parse( myTextBox.Text );
}
catch( FormatException ex )
{
MessageBox.Show( "You entered a bad number, stupid!", "Bleh!" );
}