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. ASP.NET
  4. regular expression

regular expression

Scheduled Pinned Locked Moved ASP.NET
regex
5 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.
  • F Offline
    F Offline
    fififlowertot
    wrote on last edited by
    #1

    Hi, I want to check if the string ends with '-0000' when all the remaining characters are numbers. I tried Regex.IsMatch(mystring, @"\d*(0){4}") but it returns true even when there is no '-' which regular expression to check with for a string which ends with '-0000'

    S R A 3 Replies Last reply
    0
    • F fififlowertot

      Hi, I want to check if the string ends with '-0000' when all the remaining characters are numbers. I tried Regex.IsMatch(mystring, @"\d*(0){4}") but it returns true even when there is no '-' which regular expression to check with for a string which ends with '-0000'

      S Offline
      S Offline
      Sneha Bisht
      wrote on last edited by
      #2

      one more method u can check enter value on server side or in page.

      S 1 Reply Last reply
      0
      • S Sneha Bisht

        one more method u can check enter value on server side or in page.

        S Offline
        S Offline
        Sneha Bisht
        wrote on last edited by
        #3

        try [.\-0000] in expression

        1 Reply Last reply
        0
        • F fififlowertot

          Hi, I want to check if the string ends with '-0000' when all the remaining characters are numbers. I tried Regex.IsMatch(mystring, @"\d*(0){4}") but it returns true even when there is no '-' which regular expression to check with for a string which ends with '-0000'

          R Offline
          R Offline
          Ravi Sant
          wrote on last edited by
          #4

          This one worked for me:

          System.Text.RegularExpressions.Regex.IsMatch(str, @"[.\-]\d*(0){4}");

          when tested:

          bool b1 = Do("10.0000"); //false
          b1 = Do("10-0000"); //true
          b1 = Do("10-0000/"); //true
          b1 = Do("10-0000."); //true
          b1 = Do("10-0000/-"); //true

          where Do() is

          private bool Do(string str) { return System.Text.RegularExpressions.Regex.IsMatch(str, @"[.\-]\d*(0){4}"); }

          ♫ 99 little bugs in the code, 99 bugs in the code We fix a bug, compile it again 101 little bugs in the code ♫

          1 Reply Last reply
          0
          • F fififlowertot

            Hi, I want to check if the string ends with '-0000' when all the remaining characters are numbers. I tried Regex.IsMatch(mystring, @"\d*(0){4}") but it returns true even when there is no '-' which regular expression to check with for a string which ends with '-0000'

            A Offline
            A Offline
            AspDotNetDev
            wrote on last edited by
            #5

            fififlowertot wrote:

            when all the remaining characters are numbers

            Not sure what you mean by that. However, the following regex will ensure the string ends with a dash followed by exactly 4 numeric digits.

            -[0-9]{4}$

            If you want to ensure the whole string is zero or more numeric digits followed by a dash followed by exactly 4 zeroes, this would work:

            ^[0-9]*-0{4}$

            [

            S<T>::f(U) // Out of line.

            ](http://msdn.microsoft.com/en-us/library/8yk3t00s(v=vs.71).aspx)

            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