MFC: verifying Edit Control input

I'm having some trouble verifying MFC Edit Box data (the box where users type in data). Here's what I need to verify:

- the user types an integer into the edit box, which can be negative
- the verification function should ensure the integer is within a certain range
- if it is an illegal value, it must be changed to some default legal value

The verification function is trivial, but what Edit Box event it is attached to is causing issues. Right now I have the input verification even attached to "EN_CHANGE" but that seems to be causing problems since it runs on every character types. Is there a more appropriate input to attach the verification function to?

Is there a way to not verify the Edit Box data until the user is done inputting? Perhaps by hitting enter or something?
Who is Participating?
alb66Connect With a Mentor Commented:
You must handle EN_KILLFOCUS:

      ON_EN_KILLFOCUS(IDC_EDIT1, OnEnKillfocusEdit1)

void CYourDlg::OnEnKillfocusEdit1()
      // do something here...
See ("Validating Edit Controls") - this article comes with full source code and demonstrates how to do that.
jkrConnect With a Mentor Commented:
Sorry, wrong link, the above is managed code. See ("Validating Edit Controls"). The same applies, full source code - even the author is the same person.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.