how to validate field from jquery

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
Hello All,

how to validate from field from in jquery. i have created model validator

below is my code.


@model EmailChangeModel
@using Nop.Web.Models.Customer;
@using Nop.Core;
@{
    Layout = "";
}


@using (Html.BeginForm(null, null, new { id = "ChangeEmail" }))
{
    @Html.AntiForgeryToken()
    <div class="message-error">
        @Html.ValidationSummary(true)
    </div>
    if (!String.IsNullOrEmpty(Model.Result))
    {
        <div class="result">
            @Model.Result
        </div>
    }
  <div class="inputs">
                        @Html.LabelFor(model => model.Email, new { }, ":")
                        @Html.RequiredHint()
                        @Html.EditorFor(model => model.Email)
                        @Html.ValidationMessageFor(model => model.Email)
                    </div>
                    <div class="inputs">
                        @Html.LabelFor(model => model.ConfirmEmail, new { }, ":")
                        @Html.RequiredHint()
                        @Html.EditorFor(model => model.ConfirmEmail)
                        @Html.ValidationMessageFor(model => model.ConfirmEmail)
                    </div>

    <div class="buttons">
        <input type="submit" value="Change Email Address" name="save-info-button" class="button-1 save-customer-info-button" id="btnChageEmail" />
        <script type="text/javascript">
            $(document).ready(function () {
                $("#Email").val("");
                $("#ConfirmEmail").val("");

                $('#btnChageEmail').click(function (e) {
                  
                    AjaxCart.setLoadWaiting(true);
                    var email = $('#Email').val();
                    if(email=="")
                    return false;
                    var confirmEmail = $('#ConfirmEmail').val();

                    $.ajax({
                        cache: false,
                        type: "POST",
                        url: "@(Url.RouteUrl("ChangeEmailPost"))",
                        data: { "Email": email, "ConfirmEmail": confirmEmail },
                        success: function (data) {
                            $("#changeEmaildiv").html(data.Result);
                            AjaxCart.setLoadWaiting(false);
                        },
                        error: function (xhr, ajaxOptions, thrownError) {
                            AjaxCart.setLoadWaiting(false);
                        }
                      
                    });
                    
            });
        });
        </script>
    </div>

}
9 years ago
i have write code as

   $("#ChangeEmail").valid();

but now i am getting error.

4
TypeError: this[0] is undefined
  

...)return this.validate().form();var e=!0,i=t(this[0].form).validate();return this...

  
in jquery.validate.min.js file.


Thanks is advance.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.