Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to validate input entered in Edit control MFC vc++

How to validate input entered in Edit control MFC vc++

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasetutorialquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_14575556
    wrote on last edited by
    #1

    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. :)

    _ M V 3 Replies Last reply
    0
    • M Member_14575556

      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. :)

      _ Offline
      _ Offline
      _Flaviu
      wrote on last edited by
      #2

      You can find right here some CEdit derived control which have what you want: Validating Edit Controls[^], A Validating Edit Control[^], and so on ...

      M 1 Reply Last reply
      0
      • M Member_14575556

        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. :)

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #3

        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!

        M 1 Reply Last reply
        0
        • M Member_14575556

          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. :)

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #4

          Have a look at [CEdit::ShowBalloonTip](https://docs.microsoft.com/en-us/cpp/mfc/reference/cedit-class?view=vs-2019#showballoontip)

          M 1 Reply Last reply
          0
          • M Maximilien

            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!

            M Offline
            M Offline
            Member_14575556
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • _ _Flaviu

              You can find right here some CEdit derived control which have what you want: Validating Edit Controls[^], A Validating Edit Control[^], and so on ...

              M Offline
              M Offline
              Member_14575556
              wrote on last edited by
              #6

              Thank you :)

              1 Reply Last reply
              0
              • V Victor Nijegorodov

                Have a look at [CEdit::ShowBalloonTip](https://docs.microsoft.com/en-us/cpp/mfc/reference/cedit-class?view=vs-2019#showballoontip)

                M Offline
                M Offline
                Member_14575556
                wrote on last edited by
                #7

                Thank you.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups