Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

form validation jquery input array

$("#passenger_info").validate({
  errorPlacement: $.noop,
  ignore: ".ignore_val",
  rules: {},

  invalidHandler: function (form, validator) {
    var errors = validator.numberOfInvalids();
    if (errors) {
      validator.errorList[0].element.focus();
    }
    $("input.first-name").each(function () {
      if ($(this).val() == "" && $(this).val().length < 1) {
        $(this).addClass("error");
      } else {
        $(this).removeClass("error");
      }
    });
  },

  submitHandler: function (form) {
    var isValid = true;
    $("input.first-name").each(function () {
      if ($(this).val() == "" && $(this).val().length < 1) {
        $(this).addClass("error");
        isValid = false;
      } else {
        $(this).removeClass("error");
      }
    });

    if (isValid) {
      form.submit();
    }
  },
});
Source by github.com #
 
PREVIOUS NEXT
Tagged: #form #validation #jquery #input #array
ADD COMMENT
Topic
Name
1+4 =