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. RegEx with < or >

RegEx with < or >

Scheduled Pinned Locked Moved C#
questionregextutorialworkspace
9 Posts 4 Posters 1 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.
  • E Offline
    E Offline
    econner
    wrote on last edited by
    #1

    Hello, I am trying to setup a RegEx expresion to check a text box for numeric values but also have the possibility to have a < or > symbol. For example the input could be 25.1 or > 20 or < 50, etc. How can I allow for the < or > symbol? Thanks

    P P 2 Replies Last reply
    0
    • E econner

      Hello, I am trying to setup a RegEx expresion to check a text box for numeric values but also have the possibility to have a < or > symbol. For example the input could be 25.1 or > 20 or < 50, etc. How can I allow for the < or > symbol? Thanks

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

      There is a Regular Expressions forum. How about something as simple as: ^(\s|\d|\.|<|>)*$ (not tested).

      1 Reply Last reply
      0
      • E econner

        Hello, I am trying to setup a RegEx expresion to check a text box for numeric values but also have the possibility to have a < or > symbol. For example the input could be 25.1 or > 20 or < 50, etc. How can I allow for the < or > symbol? Thanks

        P Offline
        P Offline
        Peter_in_2780
        wrote on last edited by
        #3

        If you don't want to allow any spaces, try ^[<>]?\d+\.?\d*$ That scans as

        ^ beginning of string
        [<>]? < or >, zero or one times
        \d+ one or more digits
        \.? zero or one decimal points
        \d* zero or more digits
        $ end of string

        Ran a few cases past Expresso and they look OK. If you want to allow scientific notation, etc, grab the examples from Expresso (see our Free Tools forum for a link) and splice in the [<>]? bit. This one won't allow .3 or >.6 - it requires a digit before a decimal point, but a few minutes with Expresso will get you anywhere. Cheers, Peter ps As the previous answer indicated, the Regular Expressions forum would be more appropriate next time.

        Software rusts. Simon Stephenson, ca 1994.

        OriginalGriffO E 2 Replies Last reply
        0
        • P Peter_in_2780

          If you don't want to allow any spaces, try ^[<>]?\d+\.?\d*$ That scans as

          ^ beginning of string
          [<>]? < or >, zero or one times
          \d+ one or more digits
          \.? zero or one decimal points
          \d* zero or more digits
          $ end of string

          Ran a few cases past Expresso and they look OK. If you want to allow scientific notation, etc, grab the examples from Expresso (see our Free Tools forum for a link) and splice in the [<>]? bit. This one won't allow .3 or >.6 - it requires a digit before a decimal point, but a few minutes with Expresso will get you anywhere. Cheers, Peter ps As the previous answer indicated, the Regular Expressions forum would be more appropriate next time.

          Software rusts. Simon Stephenson, ca 1994.

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          :thumbsup:

          Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          • P Peter_in_2780

            If you don't want to allow any spaces, try ^[<>]?\d+\.?\d*$ That scans as

            ^ beginning of string
            [<>]? < or >, zero or one times
            \d+ one or more digits
            \.? zero or one decimal points
            \d* zero or more digits
            $ end of string

            Ran a few cases past Expresso and they look OK. If you want to allow scientific notation, etc, grab the examples from Expresso (see our Free Tools forum for a link) and splice in the [<>]? bit. This one won't allow .3 or >.6 - it requires a digit before a decimal point, but a few minutes with Expresso will get you anywhere. Cheers, Peter ps As the previous answer indicated, the Regular Expressions forum would be more appropriate next time.

            Software rusts. Simon Stephenson, ca 1994.

            E Offline
            E Offline
            econner
            wrote on last edited by
            #5

            Thanks everyone for the suggestions. They have helped get started but the criteria has changed. I now need to support the following conditions: 1. a value of N/A only in the field => N/A 2. a numeric value with decimal points => 24.231 3. a numeric value that can begin with < character => < 12.1, or < .5 4. a numeric value that can begin with > character => > 27.2, or > .5

            P 1 Reply Last reply
            0
            • E econner

              Thanks everyone for the suggestions. They have helped get started but the criteria has changed. I now need to support the following conditions: 1. a value of N/A only in the field => N/A 2. a numeric value with decimal points => 24.231 3. a numeric value that can begin with < character => < 12.1, or < .5 4. a numeric value that can begin with > character => > 27.2, or > .5

              P Offline
              P Offline
              Peter_in_2780
              wrote on last edited by
              #6

              Before we go any further, let's settle on the spec. Is N/A required to be uppercase? Are any or all of n/a N/a n/A acceptable? From your example, .12 is OK. What about 13. ? Is an integer value like 123 (no decimal point) allowed? Are there limits on the number of digits (total/before/after the decimal point)? Your answers to these questions do not affect the solvability of the problem (the existence of a suitable regex), but they do affect the solution (the value of the regex). Cheers, Peter

              Software rusts. Simon Stephenson, ca 1994.

              E 1 Reply Last reply
              0
              • P Peter_in_2780

                Before we go any further, let's settle on the spec. Is N/A required to be uppercase? Are any or all of n/a N/a n/A acceptable? From your example, .12 is OK. What about 13. ? Is an integer value like 123 (no decimal point) allowed? Are there limits on the number of digits (total/before/after the decimal point)? Your answers to these questions do not affect the solvability of the problem (the existence of a suitable regex), but they do affect the solution (the value of the regex). Cheers, Peter

                Software rusts. Simon Stephenson, ca 1994.

                E Offline
                E Offline
                econner
                wrote on last edited by
                #7

                Basically, I have a field that either can take an integer value up to 3 digits or a decimal value with up to 2 decimal places. I change the mask in code before the screen is displayed. Below is an example of the existing masks. TextBox1.Mask ='\d?\d?\d?'; OR TextBox1.Mask = '\d+.\d?\d?'; Now, I need to have the integer mask have the ability to accept a <, > or N/A as well as to have the decimal mask do the same. I need it in two masks because I dont want certain fields to be able to enter decimal values and other fields to have the ability. I also can set the textbox to foce upper case for (N/A) and set a max length if needed.

                P 1 Reply Last reply
                0
                • E econner

                  Basically, I have a field that either can take an integer value up to 3 digits or a decimal value with up to 2 decimal places. I change the mask in code before the screen is displayed. Below is an example of the existing masks. TextBox1.Mask ='\d?\d?\d?'; OR TextBox1.Mask = '\d+.\d?\d?'; Now, I need to have the integer mask have the ability to accept a <, > or N/A as well as to have the decimal mask do the same. I need it in two masks because I dont want certain fields to be able to enter decimal values and other fields to have the ability. I also can set the textbox to foce upper case for (N/A) and set a max length if needed.

                  P Offline
                  P Offline
                  Peter_in_2780
                  wrote on last edited by
                  #8

                  OK. Here are a couple: *note* these are regexes, which may or may not be suitable for use directly in a maskedit control mask field. integer, 1 - 3 digits with N/A < > ^(N/A)|([<>]?\d{1,3})$ float, 0 - 2 decimal places, with the same extras ^(N/A)|([<>]?\d+\.\d{0,2})$ This one requires at least one digit before the decimal point. If you want to allow .12 change the + in the middle to * . Following the "teach a man to fish" philosophy, I strongly recommend you get yourself a copy of the free tool Expresso[^] (I have no connection to Ultrapico other than as a very satisfied user.) Cheers, Peter [edit] added *note* [/edit]

                  Software rusts. Simon Stephenson, ca 1994.

                  modified on Wednesday, August 3, 2011 9:17 PM

                  E 1 Reply Last reply
                  0
                  • P Peter_in_2780

                    OK. Here are a couple: *note* these are regexes, which may or may not be suitable for use directly in a maskedit control mask field. integer, 1 - 3 digits with N/A < > ^(N/A)|([<>]?\d{1,3})$ float, 0 - 2 decimal places, with the same extras ^(N/A)|([<>]?\d+\.\d{0,2})$ This one requires at least one digit before the decimal point. If you want to allow .12 change the + in the middle to * . Following the "teach a man to fish" philosophy, I strongly recommend you get yourself a copy of the free tool Expresso[^] (I have no connection to Ultrapico other than as a very satisfied user.) Cheers, Peter [edit] added *note* [/edit]

                    Software rusts. Simon Stephenson, ca 1994.

                    modified on Wednesday, August 3, 2011 9:17 PM

                    E Offline
                    E Offline
                    econner
                    wrote on last edited by
                    #9

                    Thanks for the assistance and thanks for the link to Expresso.

                    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