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 restrict edit control to accept only english language characters

How to restrict edit control to accept only english language characters

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
10 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.
  • S Offline
    S Offline
    Suyash
    wrote on last edited by
    #1

    Do we have any way to restrict the edit control to only support accepting english characters/numbers?. If we make a simple edit control i.e. non-rich edit control, is it dependent on the target system and the keyboard settings that edit control accepts the character, for eg. if we create a simple edit control, and run our application on chinese system, would the user be able to type in chinese characters in to this control, if yes, is there any way to force the user to enter the text only in english language irrespective of his system language. Thanks for you responses in advance! Regards Suyash

    T D 2 Replies Last reply
    0
    • S Suyash

      Do we have any way to restrict the edit control to only support accepting english characters/numbers?. If we make a simple edit control i.e. non-rich edit control, is it dependent on the target system and the keyboard settings that edit control accepts the character, for eg. if we create a simple edit control, and run our application on chinese system, would the user be able to type in chinese characters in to this control, if yes, is there any way to force the user to enter the text only in english language irrespective of his system language. Thanks for you responses in advance! Regards Suyash

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      override the WM_CHAR even for that editBox... but as David told, consider seriously thinking about why you need this (what problem you're trying to solve), and if you cannot solve your problem another way...

      W 1 Reply Last reply
      0
      • S Suyash

        Do we have any way to restrict the edit control to only support accepting english characters/numbers?. If we make a simple edit control i.e. non-rich edit control, is it dependent on the target system and the keyboard settings that edit control accepts the character, for eg. if we create a simple edit control, and run our application on chinese system, would the user be able to type in chinese characters in to this control, if yes, is there any way to force the user to enter the text only in english language irrespective of his system language. Thanks for you responses in advance! Regards Suyash

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

        Suyash wrote:

        ...is there any way to force the user to enter the text only in english language irrespective of his system language.

        Is that useful? Wouldn't that be irritating to the Chinese user?


        "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

        "There is no death, only a change of worlds." - Native American Proverb

        S 1 Reply Last reply
        0
        • T toxcct

          override the WM_CHAR even for that editBox... but as David told, consider seriously thinking about why you need this (what problem you're trying to solve), and if you cannot solve your problem another way...

          W Offline
          W Offline
          Waldermort
          wrote on last edited by
          #4

          With Richedit controls you can set the EM_NOIME style, this will prevent the user from being able to type chinese characters.Edit controls do not have this feature so you would have to go one step further and handle the WM_IME_CHAR and WM_IME_COMPOSITION yourself. But they would still have the option of being able to paste. Really there is no simple way to prevent it. You could override the WM_CHAR, but this would involve comparing each character entered against those in the charset GB5 for traditional and GB2312 for simplified. Or limit it even further by only allowing charcters a-z and A-Z, but here you would have problems telling the difference between single byte and multibyte characters. Another option is to set the font for the control to a font other than system and chinese. This would cause the control to display a special character (usually a box,star or Question mark) for those characters not found in the font.

          T D 2 Replies Last reply
          0
          • W Waldermort

            With Richedit controls you can set the EM_NOIME style, this will prevent the user from being able to type chinese characters.Edit controls do not have this feature so you would have to go one step further and handle the WM_IME_CHAR and WM_IME_COMPOSITION yourself. But they would still have the option of being able to paste. Really there is no simple way to prevent it. You could override the WM_CHAR, but this would involve comparing each character entered against those in the charset GB5 for traditional and GB2312 for simplified. Or limit it even further by only allowing charcters a-z and A-Z, but here you would have problems telling the difference between single byte and multibyte characters. Another option is to set the font for the control to a font other than system and chinese. This would cause the control to display a special character (usually a box,star or Question mark) for those characters not found in the font.

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #5

            Walder, welcome back ;P i'm sorry to be opposed to you again, but i'm not the one who asked the question ;) sorry for the disapointment :->

            W 1 Reply Last reply
            0
            • T toxcct

              Walder, welcome back ;P i'm sorry to be opposed to you again, but i'm not the one who asked the question ;) sorry for the disapointment :->

              W Offline
              W Offline
              Waldermort
              wrote on last edited by
              #6

              LOL, don't worry. I'm just under a bit of pressure to get this application finished. But one things for sure, I won't be asking questions again if I can help it.

              T 1 Reply Last reply
              0
              • W Waldermort

                LOL, don't worry. I'm just under a bit of pressure to get this application finished. But one things for sure, I won't be asking questions again if I can help it.

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #7

                lol hey, don't worry, i'm cool ;) if you have particuliar points that you cannot find/understand/learn alone, then I'd be glad to help you in this :-D cheers, :rose:

                1 Reply Last reply
                0
                • W Waldermort

                  With Richedit controls you can set the EM_NOIME style, this will prevent the user from being able to type chinese characters.Edit controls do not have this feature so you would have to go one step further and handle the WM_IME_CHAR and WM_IME_COMPOSITION yourself. But they would still have the option of being able to paste. Really there is no simple way to prevent it. You could override the WM_CHAR, but this would involve comparing each character entered against those in the charset GB5 for traditional and GB2312 for simplified. Or limit it even further by only allowing charcters a-z and A-Z, but here you would have problems telling the difference between single byte and multibyte characters. Another option is to set the font for the control to a font other than system and chinese. This would cause the control to display a special character (usually a box,star or Question mark) for those characters not found in the font.

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

                  waldermort wrote:

                  With Richedit controls you can set the EM_NOIME style...

                  Perhaps you meant ES_NOIME?


                  "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                  "There is no death, only a change of worlds." - Native American Proverb

                  W 1 Reply Last reply
                  0
                  • D David Crow

                    waldermort wrote:

                    With Richedit controls you can set the EM_NOIME style...

                    Perhaps you meant ES_NOIME?


                    "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                    "There is no death, only a change of worlds." - Native American Proverb

                    W Offline
                    W Offline
                    Waldermort
                    wrote on last edited by
                    #9

                    haha, so I did. I have no excuse, the 'S' and 'M' are too far apart to blame the keyboard. So, if anybody ask's, it was the wife ;)

                    1 Reply Last reply
                    0
                    • D David Crow

                      Suyash wrote:

                      ...is there any way to force the user to enter the text only in english language irrespective of his system language.

                      Is that useful? Wouldn't that be irritating to the Chinese user?


                      "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                      "There is no death, only a change of worlds." - Native American Proverb

                      S Offline
                      S Offline
                      Suyash
                      wrote on last edited by
                      #10

                      DavidCrow wrote:

                      Is that useful? Wouldn't that be irritating to the Chinese user?

                      Hello All, Thanks for your replies and suggestion to the given problem, I would try to apply ES_NOIME solution as suggested. Regarding this requirement, actually we do have a poker table client, wherein various players from various contries(usa, china etc. etc.) will be able to play on the same table. Each player may have his/her own different language version of our software. However we also provide a chat facility, its all lobby chat, and personal chat is allowed. and its possible that 2 chinese player, if allowed to chat in chinese language(which other players may not know), can collude and cheat other players, so thats the reason we wish to restrict the chat input window to support only the english characters. Though we understand that there is no way to prohibit languages that uses english character set, like german. Thanks again! Regards Suyash

                      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