Validating text in textbox

  • Thread starter Thread starter Steffo
  • Start date Start date
S

Steffo

Hi

I'm using vc++ and windows forms. Hiw can validate that the user have
inserted a float value in a texbox.

/S
 
Hi

I'm using vc++ and windows forms. Hiw can validate that the user have
inserted a float value in a texbox.

/S

try{
float.Parse(text)
//good input
}
catch(Exception e)
{
//bad input
}
 
I prefer the use of double.TryParse().

The following code would do the trick:

double resNum;
if( Double.TryParse(s, NumberStyles.Number, NumberFormatInfo.InvariantInfo,
out resNum ) == false )
[Your error handling code]
else
[Use resNum as the parsed value]

Tom Clement
Apptero, Inc.
 

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

Similar Threads

TextBox lost focus 2
Access Userform validation rule wont work - Please help 0
help on richtextbox 3
Validation in MDI children 1
edit a bound textbox control on a form 3
SetTempVar 2
Null and bound textbox 1
Validators 8

Back
Top