Karthik K

Karthik K

  • 1k
  • 738
  • 191.7k

Regular validation express in asp.net

Jan 31 2024 9:56 AM

Hi ,

 How to not proceed the button click event on the regularvalidationexpression go on Invalid ,Can anyone suggest with example code .the validation working fine but its allow the click event on the codebehind .

source code : 

<div class="row">
    <!-- ============================================================== -->
    <!-- basic form -->
    <!-- ============================================================== -->
    <div class="col-xl-6 col-lg-6 col-md-12 col-sm-12 col-12">
        <div class="card">
            <h5 class="card-header">Change Password </h5>
            <div class="card-body">
                <form action="#" id="basicform" data-parsley-validate="">
                <br />
                    <div class="form-group">
                        <label for="inputUserName">Old Password </label>
                        <asp:TextBox ID="txtOldPassword" runat="server" TextMode="Password" autocomplete="off" class="form-control"></asp:TextBox>
                    </div>

                    <div class="form-group">
                        <label for="inputPassword">Password</label>
                        <asp:TextBox ID="txtNewPassword" ValidationGroup="chkcharacters" runat="server" TextMode="Password" autocomplete="off"  class="form-control">
                           </asp:TextBox>
                    </div>
                    <div class="form-group">
                        <label for="inputRepeatPassword">Repeat Password</label>
                        <asp:TextBox ID="txtRepeatPassword" ValidationGroup="chkcharacters" runat="server" TextMode="Password" autocomplete="off"  class="form-control"></asp:TextBox>
                    </div>
                    <div class="row">
                       &nbsp; &nbsp; &nbsp;<asp:Button ID="btnSave" runat="server" Text="Save" ValidationGroup="chkcharacters"
                            class="btn btn-space btn-primary" onclick="btnSave_Click" OnClientClick="return validate()" CausesValidation="true" />
                    </div>
                    <div>
                       <asp:RegularExpressionValidator ID="Regex5" runat="server" ControlToValidate="txtNewPassword" ValidationGroup="chkcharacters"
                            ValidationExpression="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,12}" Display="Dynamic"
                            ErrorMessage="<BR>Password must contain:<br> Minimum 8 and Maximum 12 characters<BR>Atleast 1 UpperCase Alphabet,<BR> 1 LowerCase Alphabet, <BR>1 Number and 1 Special Character"
                            ForeColor="Red" />

                      <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtRepeatPassword"
                            ValidationExpression="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,12}"
                            ErrorMessage="<BR>Password must contain: <br>Minimum 8 and Maximum 12 characters<br> atleast 1 UpperCase Alphabet,<br> 1 LowerCase Alphabet,<br> 1 Number and 1 Special Character"
                            ForeColor="Red" />
                         <div class="form-group"> 
                         <label for="inputRepeatPassword" style="color:Blue"> ** You should change the Default Password with Strong Password **</label>                                           
                         <label for="inputRepeatPassword" style="color:Blue"> ** Your Password should contains 1 Uppercase,1 Alphabet </label>
                         <label for="inputRepeatPassword" style="color:Blue">  1 Lowercase,1 Number,1 Special Character ** </label>                                           
                        </div>
                </form>
            </div>
        </div>
    </div>
</div>

 Thanks in advance 

Karthik.K 


Answers (4)