jquery-form-validation

Validating form with jquery

View the Project on GitHub Swastikyadav/jquery-form-validation

Form validation with JQuery and JQuery Validate Plugin.

Step: 1

Add these two script at top of your HTML file.

JQuery CDN link

JQuery Validate CDN link

Step: 2

Step: 3

$(function() {
  $("#loginForm").validate({
    rules: {
      email: {
        required: true,
        email: true,
      },
      password: {
        required: true,
        minlength: 5,
      }
    },

    messages: {
      email: {
        required: "Please enter a valid email address.",
      },
      password: {
        required: "Please provide a password.",
        minlength: "Password is too short. Minimum length is 5."
      }
    },

    submitHandler: function(form) {
      form.submit();
    }
  })
})

Step: 4

form .error {
  color: red;
}
And that’s how you validate your form with JQuery.