locked
Regular Expression Validation - Range of numbers RRS feed

  • Question

  • I am trying to update some old code that was created by a person quite a few years ago.

    I am trying to validate a range from G 07 000000 to G 11 000000 (or G07000000 to G11000000).

    The code was:

    <asp:RegularExpressionValidator ID="RegularExpressionValidator_Card"

                runat="server" ControlToValidate="tbBarcode" Display="Dynamic"

                ErrorMessage="Sorry, but you do not appear to be authorised to view these references."

                ValidationExpression="(G|g)0(7|8)\d{6}"></asp:RegularExpressionValidator>

    and I changed it to:

    <asp:RegularExpressionValidator ID="RegularExpressionValidator_Card"

                runat="server" ControlToValidate="tbBarcode" Display="Dynamic"

                ErrorMessage="Sorry, but you do not appear to be authorised to view these references."

                ValidationExpression="(G|g)(07|08|09|10|11)\d{6}"></asp:RegularExpressionValidator>

    It validated a range between G07000000 and G09999999 but when I try G10000000, it won't validate.

    I am not a developer so am unsure what the "ValidationExpression" should be. 

    Any help appreciated :)

    Friday, August 30, 2019 12:31 AM

Answers

  • That should work.  Are you SURE you typed seven zeros when you did your test?  It would be pretty easy to confuse G1000000 and G10000000.

    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    • Proposed as answer by D Avik Friday, August 30, 2019 5:12 AM
    • Marked as answer by WDC Online Wednesday, September 4, 2019 4:07 AM
    Friday, August 30, 2019 4:57 AM

All replies

  • That should work.  Are you SURE you typed seven zeros when you did your test?  It would be pretty easy to confuse G1000000 and G10000000.

    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    • Proposed as answer by D Avik Friday, August 30, 2019 5:12 AM
    • Marked as answer by WDC Online Wednesday, September 4, 2019 4:07 AM
    Friday, August 30, 2019 4:57 AM
  • Hi

    According to your validation regex, it will allow G07000000 and G11999999. If you just want to match G07000000 and G09999999.

    I suggest you could try below regex:

    (G|g)(07|08|09)\d{6}

    Result:

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, August 30, 2019 5:49 AM
  • It did work in the end.  There were some issues deploying it to the server that it was on.  Thank you :)
    Wednesday, September 4, 2019 4:08 AM