locked
RegExpressionValidator not working correctly for phone number RRS feed

  • Question

  • User-73739142 posted

    No matter what I input, it returns with the error message. I can't seem to get the right input settings down so that the form goes through.

    Here is my code:

    <asp:Label ID="lblPhone" runat="server" Text="Phone number"></asp:Label>
    <asp:TextBox ID="txtPhone" runat="server" TextMode="Phone" MaxLength="11"></asp:TextBox>
    <asp:RegularExpressionValidator ID="REVPhone" runat="server" ControlToValidate="txtPhone" ErrorMessage="Please enter your phone number" ForeColor="Red" ValidationExpression="&quot;^([0-9\(\)\/\+ \-]*)$&quot;"></asp:RegularExpressionValidator>

    Tuesday, November 19, 2019 11:25 PM

All replies

  • User1535942433 posted

    Hi Brad1401,

    According to your code, I suggest  you could Remove the " / ".

    Because /^([0-9\(\)\/\+ \-]*)$/   is a regular expression object for JavaScript. 

    ^([0-9\(\)\/\+ \-]*)$  is generic regular expression pattern.

    More details, you could refer to below codes:

     <div>
    
                <asp:Label ID="lblPhone" runat="server" Text="Phone number"></asp:Label>
    
                <asp:TextBox ID="txtPhone" runat="server" TextMode="Phone" MaxLength="11"></asp:TextBox>
    
                <asp:RegularExpressionValidator ID="REVPhone" runat="server" ControlToValidate="txtPhone" ErrorMessage="Please enter your phone number" ForeColor="Red" ValidationExpression="^([0-9\(\)\/\+ \-]*)$"></asp:RegularExpressionValidator>
    
            </div>

    Result:

    Best regards,

    Yijing Sun

    Wednesday, November 20, 2019 7:32 AM