How to validate input entered in Edit control MFC vc++
-
Hello everyone, I'm trying to validate user input entered in Edit control. When it is empty or user enter invalid input or enter input that is not in the database to display some message saying "invalid input" right under the edit control box as a text. What will be the best way to do this. Any suggestions? Thanks in advance. :)
-
Hello everyone, I'm trying to validate user input entered in Edit control. When it is empty or user enter invalid input or enter input that is not in the database to display some message saying "invalid input" right under the edit control box as a text. What will be the best way to do this. Any suggestions? Thanks in advance. :)
You can find right here some CEdit derived control which have what you want: Validating Edit Controls[^], A Validating Edit Control[^], and so on ...
-
Hello everyone, I'm trying to validate user input entered in Edit control. When it is empty or user enter invalid input or enter input that is not in the database to display some message saying "invalid input" right under the edit control box as a text. What will be the best way to do this. Any suggestions? Thanks in advance. :)
There are 2 schools of thought on how to do it. 1. Do it "live" as the user types in value (mostly with the EN_CHANGE message); each time the user types something, use GetWindowText and start searching the Database; this is somewhat complicated as the search can take a long time compared to the speed the user types (you would need some way to stop the current search and start a new one each time a new character is typed in); warn the user with visual feedback (red highlights while the input is not valid. 2. Do it when the user clicks on the "ok" (or "search") button; on the OnOK (or "search") , get the full string with GetWindowText and do some validation and search the Database; easier to implement, you can just wait for the whole search to be done and warn user after with a simple SetWindowText to your static control (or edit control) that will display the error. Personally, I would do "2" it is simpler and quicker (unless there is a requirement to do live input validation).
I'd rather be phishing!
-
Hello everyone, I'm trying to validate user input entered in Edit control. When it is empty or user enter invalid input or enter input that is not in the database to display some message saying "invalid input" right under the edit control box as a text. What will be the best way to do this. Any suggestions? Thanks in advance. :)
Have a look at [CEdit::ShowBalloonTip](https://docs.microsoft.com/en-us/cpp/mfc/reference/cedit-class?view=vs-2019#showballoontip)
-
There are 2 schools of thought on how to do it. 1. Do it "live" as the user types in value (mostly with the EN_CHANGE message); each time the user types something, use GetWindowText and start searching the Database; this is somewhat complicated as the search can take a long time compared to the speed the user types (you would need some way to stop the current search and start a new one each time a new character is typed in); warn the user with visual feedback (red highlights while the input is not valid. 2. Do it when the user clicks on the "ok" (or "search") button; on the OnOK (or "search") , get the full string with GetWindowText and do some validation and search the Database; easier to implement, you can just wait for the whole search to be done and warn user after with a simple SetWindowText to your static control (or edit control) that will display the error. Personally, I would do "2" it is simpler and quicker (unless there is a requirement to do live input validation).
I'd rather be phishing!
Thank you. :) I'm doing the 2nd step too. One more question :) I want to show the button only when I select any one row in the list view control. What will be the best way to do this. Thanks again.
-
You can find right here some CEdit derived control which have what you want: Validating Edit Controls[^], A Validating Edit Control[^], and so on ...
Thank you :)
-
Have a look at [CEdit::ShowBalloonTip](https://docs.microsoft.com/en-us/cpp/mfc/reference/cedit-class?view=vs-2019#showballoontip)
Thank you.