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.
 
Back
Top