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#
  4. string character checking

string character checking

Scheduled Pinned Locked Moved C#
helptutorialquestion
3 Posts 2 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 Offline
    A Offline
    azusakt
    wrote on last edited by
    #1

    Hi, I'm doing a printing range option, allow user type the print range like in the Microsoft Word. for example, the range can be (1,2,4-8,10-12) now, I would like to do a validation, prevent any non-useful character inside this string (i.e. except digit, "," and "-") any faster way to do this? Thanks for your help.

    P 1 Reply Last reply
    0
    • A azusakt

      Hi, I'm doing a printing range option, allow user type the print range like in the Microsoft Word. for example, the range can be (1,2,4-8,10-12) now, I would like to do a validation, prevent any non-useful character inside this string (i.e. except digit, "," and "-") any faster way to do this? Thanks for your help.

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Yes, write a KeyPress event handler for the TextBox.

          private void tbPages\_KeyPress ( object sender , System.Windows.Forms.KeyPressEventArgs e )
          {
              if ( "0123456789,-\\b".IndexOf ( e.KeyChar ) == -1 )
              {
                  e.Handled = true ;
              }
              
              return ;
          }
      

      (\b is backspace)

      A 1 Reply Last reply
      0
      • P PIEBALDconsult

        Yes, write a KeyPress event handler for the TextBox.

            private void tbPages\_KeyPress ( object sender , System.Windows.Forms.KeyPressEventArgs e )
            {
                if ( "0123456789,-\\b".IndexOf ( e.KeyChar ) == -1 )
                {
                    e.Handled = true ;
                }
                
                return ;
            }
        

        (\b is backspace)

        A Offline
        A Offline
        azusakt
        wrote on last edited by
        #3

        Thanks so much PIEBALDconsult ~

        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