tags:

views:

57

answers:

3

I am looking for logic that converts an incorrect user input to a correct integer input. For example, a user might mistakenly type in letters within an integer input and the logic changes that input to the correct form(integer). Any ideas?

+1  A: 

For typing errors, a BK tree is often used, in conjunction with Levenshtein Distance. Here is a good explanation on how this is applied.

Daniel
+3  A: 

If you want only numeric values, you can use a numeric control instead of textbox (NumericUpDown if I remember correctly). Otherwise, you can listen to the OnKeyDown or OnKeyPress event, "see" what's inside the argument (the key typed by the user) and eventually change its input. For instance, I'm in Italy and often users use . or , for decimal separator. So I translate dot to comma while the user types. Also, when a non-number is typed, I set e.Cancel to true so nothing is appended to the text displayed.

m.bagattini
A: 

Why would you correct incorrect input? You would want to prompt the user to re-enter the information correctly and tell them to enter an integer.

pave