Questions tagged [jquery-validate]

The jQuery Validate plugin is a jQuery plugin by Jörn Zaefferer. Its purpose is to perform client-side form validation of user entered data.

The jQuery Validate plugin is a plugin by Jörn Zaefferer. Its purpose is to perform client-side form validation of user entered data.

Helpful Links:


Stack Snippet Starter Pack:

HTML - Include the plugin script someplace after the jQuery library:
(Use CDN links or host the scripts yourself)

<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.14.0/jquery.validate.js"></script>

<form id="myform" action="post.php">
  <input type="text" name="first_name" /><br/>
  <input type="text" name="last_name" /><br/>
  <input type="text" name="phone" /><br/>
  <input type="submit" />
</form>
$(document).ready(function() {  // <-- ensure form's HTML is ready

  $("#myform").validate({  // <-- initialize plugin on the form.
    // your rules and other options,
    rules: {
      first_name: {  // <-- this is the name attribute, NOT id
        required: true
      },
      last_name: {
        required: true
      },
      phone: {
        required: true,
        digits: true
      }
    }
  });

});

jsFiddle Demo: http://jsfiddle.net/2nhcfkLj/

Documented Options: http://jqueryvalidation.org/validate


Helpful questions:

Other typical issues:

  • All input elements to be validated must be enclosed within a set of <form></form> tags. The only elements that can be validated are select, textarea, certain input types, and certain elements containing the contenteditable attribute.
  • Rules are defined by input name attributes, not by id, when declared within the rules option of .validate().
  • all input elements to be validated must contain a unique name attribute. (All radio or checkbox elements within a single "grouping" may share the same name as this one grouping is considered a single data point. However, each grouping must contain a unique name.)
  • .validate() should be called once within DOM ready to initialize the plugin. Optionally use .valid() to test the form for validity and get a boolean result of that test.
  • There is no need to enclose .validate() inside of any click or submit handler. The plugin will automatically capture and handle the submit button.
  • A name with certain special characters must be enclosed in quotes when declared within the rules option of .validate().
  • Use the submitHandler callback function to deal with successfully validated forms and/or submit via ajax.
  • Use the invalidHandler callback function for invalid forms.
  • If using the highlight or unhighlight callback function, be sure to also include the other one. They are complementary and should be used together for best results.
  • By default, the plugin will ignore any hidden input elements. This can be prevented by setting the ignore option to ignore: [] (ignore nothing; validate everything).
  • If you have multiple submit buttons where one (such as "save") needs to bypass validation but still needs to submit the form data, use class="cancel" on the button.

Related tags

6769 questions
2
votes
2 answers

jquery validation plugin for form

I am trying to validate a form having two fields string email and file type file (one of the two is mandatory). I am validating the form with following code, $("#addOrganizationMembersForm").validate({ rules : { csv : { …
Shahzeb Khan
  • 3,582
  • 8
  • 45
  • 79
2
votes
1 answer

Regex and jQuery: lower case

I would like to validate my form with jquery validation plugin. I added a method for on input: $.validator.addMethod("testRegex", function(value, element) { return this.optional(element) || /^[a-z0-9-_]+$/i.test(value); }, "test must contain…
Stephane
  • 79
  • 1
  • 7
2
votes
2 answers

JQuery validator how to remove error messages and add border coloring instead

$('.register_form').validate({ invalidHandler: function(){ return false; } I've tried this but doesn't worked, how do I remove the error messages, and instead color the input border to red? didn't find examples at docs
yeah its me
  • 1,131
  • 4
  • 18
  • 27
2
votes
3 answers

jQuery-validate - Required validation on tab out

I am using jquery.validate.js for my front end validations. The email and other validations work on tab out, but the required validations work only on submitting the form. Is it possible to have all my required validations to work on tab-out as…
Anuj
  • 1,203
  • 3
  • 13
  • 20
2
votes
1 answer

Jquery Validate Multiple Conditions

I'm trying to validate a field with multiple conditions. I've got validation working with a single condition, but I'm not sure how to go about adding in addl conditions. Here's what I have so far: priceEstimate: { required: function() { …
Jeremy
  • 1,141
  • 5
  • 20
  • 31
2
votes
2 answers

Uncaught TypeError: Cannot call method 'addMethod' of undefined in jquery validate

Hi I am using jQuery JavaScript Library v1.10.2 and jQuery Validation Plugin 1.11.1 and get the above error. Code $.validator.addMethod("fnType", function (value, element) { if (element.value == "-1") { return false; } else {return true;} },…
hima
  • 610
  • 3
  • 10
  • 24
2
votes
1 answer

jquery validate not loaded requirejs

I have a main module in RequireJS: require([ 'jquery', 'jquery.validate', 'jquery.validate.unobtrusive' ], function ($) { $(document).ready(function () { var validator = $("form").validate(); if…
2
votes
3 answers

jquery validation is not getting fired for checkboxes

I have a form where I am using jQuery validation to do validation from front end side. Most of the validation are working as I want it to. However , for the checkboxes, the validation not working. I have the following rules and messages in my…
Hello Universe
  • 3,248
  • 7
  • 50
  • 86
2
votes
2 answers

Why jquery validation is not working on appended elements?

I have a form and I want to add new elements as you can see in this fiddle I used append $('#cvfields').append(campos); to add this elements but the jquery validation plugin started to giving me problems. I found this in some answers related whith…
laviku
  • 531
  • 12
  • 32
2
votes
1 answer

Submitting a form with ajax after jQuery validation is successfull

Ok so I have a form that I am validating with jQuery Validation and I am trying to now submit it with AJAX. With the code below, once the form is valid and you click on submit the page reloads and the inputs are placed in the url address bar (i.e.…
Mitch Evans
  • 641
  • 3
  • 10
  • 25
2
votes
1 answer

jQuery validation and jQuery Mobile select list conflicts

First i'm using ASP.Net MVC4 and latest jQuery 2.0.3, jQuery mobile 1.3.1, jQuery UI 1.10.3 and jQuery Unobstrusive Validation Plugin 1.11.1 I got a probleme with jQuery validation.. it confounds the display text of the select list and the error…
2
votes
4 answers

ignore: ":hidden" does not work for controls with display:none

Hi I am using jquery validation to validate my aspx page. deliveryToDiv is hidden by setting document.getElementById("deliveryToDiv").style.display = "none"; This div has other controls which will be validated depending on this div's…
hima
  • 610
  • 3
  • 10
  • 24
2
votes
1 answer

Jquery validation: 'one table row one form ' does not work

my code: …
mainlove
  • 278
  • 3
  • 12
2
votes
1 answer

Form fails to submit after validation

I have the following code, validation works fine, but it doesnt submit jQuery("#form_driver").validate({ submitHandler: function(form) { //check if email exists jQuery.ajax({ type: "POST", url:…
Digital fortress
  • 737
  • 8
  • 18
  • 31
2
votes
2 answers

How do I extend ASP.NET MVC2 out-of-box validation to validate creditcard / emails?

I've been looking at the file MicrosoftMvcJQueryValidation.js which is the layer between your page and the jquery.validate object in ASP.NET MVC 2 Beta. It will allow any type of validation rule supported by jquery.validate and had additional…
Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
1 2 3
99
100