locked
Need to validate Textbox in Web Application using regular expression RRS feed

  • Question

  • User-2010964872 posted

    I have a textbox for adding a phone number or editing the phone number. I need to validate the text box such that it accepts only numbers on key pressed

    I could find solutions for windows form applications

    Friday, February 8, 2013 1:55 PM

Answers

  • User1027872733 posted

    yash

    run following

    <form>

     <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
            ControlToValidate="TextBox1" ErrorMessage="*"
            ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}"></asp:RegularExpressionValidator>
       
        </form>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 8, 2013 2:28 PM

All replies

  • User-344705538 posted

    Try this.....

    onkeydown="if (window.event.keyCode < 47 && window.event.keyCode > 58){ return false; }"

    Friday, February 8, 2013 2:27 PM
  • User1027872733 posted

    yash

    run following

    <form>

     <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
            ControlToValidate="TextBox1" ErrorMessage="*"
            ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}"></asp:RegularExpressionValidator>
       
        </form>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 8, 2013 2:28 PM