Question about checking input

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi,

how can i check that the input that the user inserts is of the type i need.
for expample if i want the user to insert only numbers how can i check that he hasn't insert letters or something else?

i hope that there is a better way then to check char by char...

thanks
 
Hi
Is this simple validation is all what you want to do, then you don't have
to check it char by char. Try to parse the whole string on your textbox as
a number ,and put this parsing part in a try block . if the parsing fails ,
you know the what was entered is not a correct number format and you can
prompt the user for that . Here you are an example of parsing the text
property of a textbox as integer.
try
{
int k = Int32.Parse(this.textBox1.Text);
}
catch (Exception exp)
{
MessageBox.Show(" you didn't enter a valid number " + exp.Message);
}
Hope this helps

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
Back
Top