A Validating Edit Control

The Solutions

The first thing I include is a validating edit control. This particular control solves a problem many users ask for: an edit control that validates floating-point input. However, you can replace the FSM with one that validates dates, times, Social Security Numbers, or any other textual form you can parse. The validation does not have to be limited to simple parsing, although it is clear from the fact that every change initiates a validation that you do not want to do some sort of database lookup on every character. In such a case, you would more likely do the validation on the WM_KILLFOCUS (OnKillFocus) event. But that's a different problem than the one this control addresses.

The way I handle this is to handle the reflected WM_COMMAND/EN_CHANGE message. When the contents change, I read the entire string and reparse it. This is one of the methodological changes from traditional getch-style input where you could simply run the FSM on each keystroke. In Windows, the keystrokes have nothing to do with the order of the content of the edit control, because the user can reposition the input caret anywhere in the string. So the entire string must be reparsed, from the start, each time. 

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil perpetrated by skilled but perverted professionals.” - Jon Ribbens