RegularExpressionValidator - display error if it *does* match RRS feed

  • Question

  • User650065176 posted

    I have a peculiar requirement. A user is supposed to fill out contact information, including Street Address. We don't want them to enter a PO Box for their street address. I have a rather complicated regex (~150 characters) that finds various combinations of "PO Box". The trouble is, I want to signal an error if they *do* type in a matching combination. There doesn't seem to be a "NotRegularExpressionValidator". Any ideas how I can do this on the client side? Thanks.

    Thursday, April 26, 2018 6:58 PM

All replies

  • User283571144 posted

    Hi dysert,

    As far as I know, the RegularExpressionValidator control doesn't contain the NotRegularExpressionValidator method.

    If you want to show the message if the street address match the regular, I suggest you could consider using customvalidator ClientValidationFunction property.

    More details, you could refer to below sample codes.

        <script type="text/javascript">
            function ClientValidateUserName(s,e) {
                var result = $("#TextBox1").val();
                var reg= /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/;
                if (reg.test(result)) {
                    alert('Yes you pass it');
                    e.IsValid = true;
                } else {
                    alert('Please input correct telphone number');
                    e.IsValid = false;  
        <form id="form1" runat="server">
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="TextBox1" 
            <asp:Button ID="Button1" runat="server" Text="Button" />

    Best Regards,


    Friday, April 27, 2018 9:15 AM
  • User650065176 posted

    Thank you, Brando. I'll give it a try.

    Friday, April 27, 2018 10:43 AM