1

So, basically I have multiple TextBoxes on my page and some of them have validations with RequiredFieldValidator.
I am using OnTextChanged event on txtMobileNo TextBox Field to fetch the data from database.
If the number exists in the database the the rest of my TextBoxes filled from server side.

Now, I am facing here a problem: my MobileNo Text Field skips the RegularExpressionValidator validation even if it is wrong.
I want to redirect to server side only if my number matches the validation logic.

<div class="col-md-4">
    <asp:Label ID="lblfortxtMobileNo" runat="server" Text="Mobile No"></asp:Label>
    <asp:TextBox ID="txtMobileNo" runat="server" AutoPostBack="true" OnTextChanged="txtMobileNo_TextChanged" MaxLength="10"></asp:TextBox>
    <asp:RequiredFieldValidator ID="rqfvtxtMobileNo" runat="server" ErrorMessage="*" ControlToValidate="txtMobileNo" Display="Dynamic" ForeColor="Red"></asp:RequiredFieldValidator><br />
    <asp:RegularExpressionValidator
        ID="RegularExpressionValidator1"
        runat="server"
        ErrorMessage="Please Enter Valid Number"
        ControlToValidate="txtMobileNo"
        Display="Dynamic"
        ForeColor="Red"
        ValidationExpression="^([0-9]{10})$"
    ></asp:RegularExpressionValidator>
</div>
<div class="col-md-4">
    <asp:Label ID="lblName" runat="server" Text="Name"></asp:Label>
    <asp:TextBox ID="txtName" runat="server" AutoPostBack="true"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="txtName" Display="Dynamic" ForeColor="Red"></asp:RequiredFieldValidator><br />
</div>
<div class="col-md-4">
    <asp:Button ID="btnSubmit" runat="server" Text="Save" OnClick="btnSubmit_Click" />
</div>

When I am set CauseValidation = "true" the result is somewhat what I want .
But it checks all the other RequiredFieldValidator validation as well before calling OnTextChanged function.
I just want to check Regular Expression Validation at this point for txtMobileNo and based on the result wants to display error.

Peter Csala
  • 17,736
  • 16
  • 35
  • 75
Manish Jha
  • 263
  • 2
  • 13
  • Welcome to StackOverflow. I've edited your wording because it was quite hard to follow and understand. If unintentionally I've changed the meaning please edit it. – Peter Csala Jul 16 '21 at 10:08
  • @PeterCsala Thank You For the Correction and edit is completely meant to my question. – Manish Jha Jul 17 '21 at 04:14

1 Answers1

1

Cross check your regex id it is look like an duplicated id here.

Flow
  • 26
  • 2