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. Web Development
  3. Regular expressions

Regular expressions

Scheduled Pinned Locked Moved Web Development
help
5 Posts 5 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.
  • J Offline
    J Offline
    john_paul
    wrote on last edited by
    #1

    I am trying to test a text box for either numbers or a null entry. I have tried using [0-9]|[:blank:]|[:space:] but it will not work. Any help would be appreciated.

    G D 2 Replies Last reply
    0
    • J john_paul

      I am trying to test a text box for either numbers or a null entry. I have tried using [0-9]|[:blank:]|[:space:] but it will not work. Any help would be appreciated.

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      [0-9] will only match one single digit. You have to specify how many digits you allow. You can also use \d instead of [0-9] \d{0,} - zero or more digits \d{1,} - one or more digits \d* - zero or more digits \d+ - one or more digits \d{0,5} - zero to five digits If you allow zero digits, that will take care of an empty entry. --- b { font-weight: normal; } -- modified at 9:13 Sunday 8th January, 2006

      G M 2 Replies Last reply
      0
      • G Guffa

        [0-9] will only match one single digit. You have to specify how many digits you allow. You can also use \d instead of [0-9] \d{0,} - zero or more digits \d{1,} - one or more digits \d* - zero or more digits \d+ - one or more digits \d{0,5} - zero to five digits If you allow zero digits, that will take care of an empty entry. --- b { font-weight: normal; } -- modified at 9:13 Sunday 8th January, 2006

        G Offline
        G Offline
        g00fyman
        wrote on last edited by
        #3

        not a regex, but how bout this

        private bool isValid(string str)
        {
        if(str == null || str == string.Empty) return false;

          foreach(char ch in str)
          {
            if(!Char.IsNumber()) return false;
          }
          return true;
        }
        

        my2c g00fy

        1 Reply Last reply
        0
        • G Guffa

          [0-9] will only match one single digit. You have to specify how many digits you allow. You can also use \d instead of [0-9] \d{0,} - zero or more digits \d{1,} - one or more digits \d* - zero or more digits \d+ - one or more digits \d{0,5} - zero to five digits If you allow zero digits, that will take care of an empty entry. --- b { font-weight: normal; } -- modified at 9:13 Sunday 8th January, 2006

          M Offline
          M Offline
          Michael Flanakin
          wrote on last edited by
          #4

          Just a note: I've had some issues using \d on some regex interpreters. If you run into problems with it, use [0-1]* (or +, depending on your purposes). Michael Flanakin Web Log

          1 Reply Last reply
          0
          • J john_paul

            I am trying to test a text box for either numbers or a null entry. I have tried using [0-9]|[:blank:]|[:space:] but it will not work. Any help would be appreciated.

            D Offline
            D Offline
            Daniel Santillanes
            wrote on last edited by
            #5

            if you are using regularexpressionvalidator control, this control doesn't check against your regex if it's empty. This behavior works ok for you, you would only need to add the validation of space to your reg expression. daniero

            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