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. prohbit shift key in edit box............

prohbit shift key in edit box............

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
15 Posts 6 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.
  • A ani_ikram

    i want to make user to only input numbers (1 to so on) but not spectial charters using shift like (%,#,@,!,^,&,*,()) etc

    S Offline
    S Offline
    SandipG
    wrote on last edited by
    #6

    If you do not want floating point numbers you can set the Numbers only property in resource editor. I hope it helps.

    Regards, Sandip.

    1 Reply Last reply
    0
    • A ani_ikram

      can u plz send me code so that i can get idea

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #7

      The below code will block the special charcters but permits alphabets and numbers

      void EditEx::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
      {
      if( !isdigit(nChar) && !isalpha( nChar ))
      {
      return;
      }
      CEdit::OnChar(nChar, nRepCnt, nFlags);
      }

      nave [OpenedFileFinder] [My Blog]

      A 1 Reply Last reply
      0
      • N Naveen

        The below code will block the special charcters but permits alphabets and numbers

        void EditEx::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
        {
        if( !isdigit(nChar) && !isalpha( nChar ))
        {
        return;
        }
        CEdit::OnChar(nChar, nRepCnt, nFlags);
        }

        nave [OpenedFileFinder] [My Blog]

        A Offline
        A Offline
        ani_ikram
        wrote on last edited by
        #8

        void EditEx::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if( !isdigit(nChar) && !isalpha( nChar )) { return; } CEdit::OnChar(nChar, nRepCnt, nFlags);} i hv used this method but its also restricting to enter float value while i want to enable float numbers as well plz tell me how to do it

        N C 2 Replies Last reply
        0
        • A ani_ikram

          void EditEx::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if( !isdigit(nChar) && !isalpha( nChar )) { return; } CEdit::OnChar(nChar, nRepCnt, nFlags);} i hv used this method but its also restricting to enter float value while i want to enable float numbers as well plz tell me how to do it

          N Offline
          N Offline
          Naveen
          wrote on last edited by
          #9

          ani_ikram wrote:

          well plz tell me how to do it

          :doh: Just modify the checking as follows if( !isdigit(nChar) && !isalpha( nChar ) && nChar != _T('.'))

          nave [OpenedFileFinder] [My Blog]

          A 1 Reply Last reply
          0
          • N Naveen

            ani_ikram wrote:

            well plz tell me how to do it

            :doh: Just modify the checking as follows if( !isdigit(nChar) && !isalpha( nChar ) && nChar != _T('.'))

            nave [OpenedFileFinder] [My Blog]

            A Offline
            A Offline
            ani_ikram
            wrote on last edited by
            #10

            thanks alot nave u really solved my problem

            N 1 Reply Last reply
            0
            • A ani_ikram

              thanks alot nave u really solved my problem

              N Offline
              N Offline
              Naveen
              wrote on last edited by
              #11

              You are welcome... :)

              nave [OpenedFileFinder] [My Blog]

              1 Reply Last reply
              0
              • A ani_ikram

                i want to make user to only input numbers (1 to so on) but not spectial charters using shift like (%,#,@,!,^,&,*,()) etc

                L Offline
                L Offline
                Le rner
                wrote on last edited by
                #12

                if you want to use only numbers than you can use number property of EditBox.

                IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

                L 1 Reply Last reply
                0
                • A ani_ikram

                  void EditEx::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if( !isdigit(nChar) && !isalpha( nChar )) { return; } CEdit::OnChar(nChar, nRepCnt, nFlags);} i hv used this method but its also restricting to enter float value while i want to enable float numbers as well plz tell me how to do it

                  C Offline
                  C Offline
                  Cedric Moonen
                  wrote on last edited by
                  #13

                  BTW, if you only wanted to have an edit control into which you can enter a float value, there are hundreds of article about that subject, you only have to search for it on codeproject. Here[^] is an example. The problem with your approach is that it is not secure: nothing prevents the user to enter a dot several time. So, instead of reinventing the wheel and rewriting the validation code all over again(it's not that trivial because, you have also to take into account that the user might delete some characters, change the cursor location, ...) why don't you look for a control that does this already ?

                  Cédric Moonen Software developer
                  Charting control [v1.5] OpenGL game tutorial in C++

                  1 Reply Last reply
                  0
                  • L Le rner

                    if you want to use only numbers than you can use number property of EditBox.

                    IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

                    L Offline
                    L Offline
                    Le rner
                    wrote on last edited by
                    #14

                    if you want to block Special character than you can subclass your edit control and handle OnChar function like this.

                    void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
                    {
                    char szBuffer[100] = {0};
                    short int nCounter = 0;
                    short int iTemp = 0;
                    int iStartChar = 0;
                    int iEndChar = 0;

                    if(nChar != VK\_BACK && nChar != VK\_TAB )
                    {
                    	if(nChar != '.' (nChar < '0' || nChar > '9') 
                    		 && (nChar < 'a' || nChar > 'z')&&(nChar < 'A' || nChar > 'Z'))//here write those character you want to enter
                    	{
                    		return;
                    	}
                    
                    		GetWindowText((LPTSTR)szBuffer, sizeof(szBuffer));
                    		
                    }
                    
                    CEdit::OnChar(nChar, nRepCnt, nFlags);
                    

                    }

                    IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

                    D 1 Reply Last reply
                    0
                    • L Le rner

                      if you want to block Special character than you can subclass your edit control and handle OnChar function like this.

                      void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
                      {
                      char szBuffer[100] = {0};
                      short int nCounter = 0;
                      short int iTemp = 0;
                      int iStartChar = 0;
                      int iEndChar = 0;

                      if(nChar != VK\_BACK && nChar != VK\_TAB )
                      {
                      	if(nChar != '.' (nChar < '0' || nChar > '9') 
                      		 && (nChar < 'a' || nChar > 'z')&&(nChar < 'A' || nChar > 'Z'))//here write those character you want to enter
                      	{
                      		return;
                      	}
                      
                      		GetWindowText((LPTSTR)szBuffer, sizeof(szBuffer));
                      		
                      }
                      
                      CEdit::OnChar(nChar, nRepCnt, nFlags);
                      

                      }

                      IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #15

                      Do you have an aversion against isalpha() and isdigit()?

                      "Love people and use things, not love things and use people." - Unknown

                      "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

                      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