Monday, 20 June 2016

one field text box and multiple validator

function valfunemail(source, args) {
            var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
         
            if ($.trim($("#txtemail").val()) == "") {
                $("#rfvtxtemail").css("display", "inline");
                $("#rfvtxtemail").css("display", "block");
                args.IsValid = false;
            } else if (reg.test($("#txtemail").val()) == false) {
                  $("#rfevtxtemail").css("display", "inline");
                $("#rfevtxtemail").css("display", "block");
                args.IsValid = false;
            } else {
                //$(".txtmobile").css("border-color", "");
                args.IsValid = true;
            }

        }



  <asp:TextBox ID="txtemail" runat="server" MaxLength="100"></asp:TextBox>
                                       
                                        <asp:RequiredFieldValidator ID="rfvtxtemail" ControlToValidate="txtemail"
                                            runat="server" ValidationGroup="paymentgp" ForeColor="red" ErrorMessage="Please enter email id"
                                            Display="Dynamic" class="errorMsg errorLeft"></asp:RequiredFieldValidator>
                                        <asp:RegularExpressionValidator ID="rfevtxtemail" runat="server" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
                                            ValidationGroup="paymentgp" ErrorMessage="Please enter valid email id" ForeColor="red"
                                            ControlToValidate="txtemail" Display="Dynamic" class="errorMsg errorLeft" />

                                             <asp:RequiredFieldValidator ID="RequiredFieldValidator5" ControlToValidate="txtemail"
                                            runat="server" ValidationGroup="paymentgp1" ForeColor="red" ErrorMessage=""
                                            Display="Dynamic" class="errorMsg errorLeft"></asp:RequiredFieldValidator>
                                        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
                                            ValidationGroup="paymentgp1" ErrorMessage="" ForeColor="red"
                                            ControlToValidate="txtemail" Display="Dynamic" class="errorMsg errorLeft" />

No comments:

Post a Comment