Textbox Input Problem

  • Thread starter Thread starter KartTalk.com
  • Start date Start date
K

KartTalk.com

Hi there,

I am very new to C# and the idea of OOP, however I do have some
non-OOP PHP background.

Anyway, here is the scenario --

I am writing a simple app to get my C# feet wet and it does distance
and volume conversions. For example 1 foot equals 12 inches ...pretty
simple stuff.

I thought all was fine until I decided to enter .25 into the textbox
(.25 foot = 3 inches) and it blew up with System.FormatException
error, so now I am trying to fix that problem and have discovered a
few others. If I enter .., it also blows up with the same error.

What I am trying to do is this:
Limit the characters that can be entered to 0-9, e and . (decimal
point/period/dot), backspace and delete should work as well. Also,
limit the number of .'s and e's to one (don't want anyone entering
..254.34 for example) --basically, catching anything that would blow it
up :)

What I have tried:
I have tried rough implementations of double.tryparse, regex.replace,
int32.parse on the textbox, but by not having an experts grasp on the
language yet, I am having no luck.

This is probably a very simple problem but the new guy has not a clue.

TIA

Mark
 
Treat the textBox entry as a string.

try
{
//convert string into number
}
catch
{
//"bad imput" message
}

That's all you need to do imo.
 
Back
Top