Regular Expression - having issues with empty string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • burnproof21
    New Member
    • Oct 2012
    • 3

    Regular Expression - having issues with empty string

    Hi, I have a textbox where I want the user to be able to enter either:

    (1). Nothing
    (2). up to 3 digits, optional decimal, up to 2 decimals.

    I've been using ^\d{0,3}(\.\d{0 ,2})?$ but it's not allowing the empty string.

    Thanks for any help!
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    That expression works fine for me. What does the code look like?

    Comment

    • burnproof21
      New Member
      • Oct 2012
      • 3

      #3
      asp.net...

      Code:
      <...ID="PercentageValidate" Display="Dynamic" ForeColor="Red" runat="server" ControlToValidate="Percentage" ValidationExpression="^\d{0,3}(\.\d{0,2})?$" ErrorMessage="Error!" />
      Last edited by Rabbit; Oct 23 '12, 07:50 PM. Reason: Please use code tags when posting code.

      Comment

      • burnproof21
        New Member
        • Oct 2012
        • 3

        #4
        Even using ^(\d{0,3}) gives me issues with an empty textbox

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          It may have to do with asp.net's specific implementation. But try checking that it's actually a blank string in the control and not a null.
          Last edited by Rabbit; Oct 23 '12, 07:56 PM.

          Comment

          • zacksoniar
            New Member
            • Sep 2007
            • 45

            #6
            ^(?!\s*$).+ try putting this

            Comment

            Working...