Dynamic jQuery Validate error messages with AddMethod based on the element

From looking at the validator source code, I think this should do it: $.validator.addMethod(‘min-length’, function (val, element) { return this.optional(element) || val.length >= $(element).data(‘min’); }, function(params, element) { return ‘The field cannot be less than than ‘ + $(element).data(‘min’) + ‘ length.’; }); In your original code, the message string is NOT within the closure; … Read more

Manually adding & removing validation errors to jQuery validator

I have solved this by overriding showErrors function in jQuery validator with my own, which is compatible with unobtrusive-generated validation spans, and cleaning up valid fields which have invalid class. It is not very nice workaround but it works. Here is jsfiddle with solution: http://jsfiddle.net/goranobradovic/ughCm/5/ UPDATE: As link to external site is not proper answer … Read more

How can we specify rules for jQuery validation plugin by class?

For the purposes of my example, this is the base starting code: HTML: <input type=”text” name=”field_1″ /> <input type=”text” name=”field_2″ /> <input type=”text” name=”field_3″ /> JS: $(‘#myForm’).validate({ rules: { field_1: { required: true, number: true }, field_2: { required: true, number: true }, field_3: { required: true, number: true } } }); DEMO: http://jsfiddle.net/rq5ra/ NOTE: … Read more

Why is jQuery Validation adding noValidate attribute?

The novalidate attribute simply tells the browser to disable the built-in HTML5 validation, or ignore any HTML5 validation attributes you may have used. The jQuery Validate plugin dynamically adds the novalidate attribute because, by installing it, you’ve decided to let the plugin handle validation instead of HTML5. Neither of those two methods, JavaScript (jQuery) or … Read more

How to validate array of inputs using validate plugin jquery

Sometimes we need to validate an array of input elements: For example – <form name=”signupForm” class=”cmxform” id=”signupForm” method=”get” action=””> <select name=”category[]” id=”cat_1″> <option value=””>Select One</option> <option value=”1″>aa</option> <option value=”2″>bb</option> <option value=”3″>cc</option> <option value=”4″>dd</option> </select> <select name=”category[]” id=”cat_2″> <option value=””>Select One</option> <option value=”5″>ee</option> <option value=”6″>ff</option> <option value=”7″>gg</option> <option value=”8″>hh</option> </select> <select name=”category[]” id=”cat_3″> <option value=””>Select One</option> … Read more

Knockout + mvc 3 + Validation

In my Mvc Controls Toolkit I developed Helpers based on the knockout library. These helpers not only help in writing the knockout code, but enhance the knockout library with Unobtrusive validation and globalization. Moreover, the binding mechanism is enhanced to include complex controls such as a DatetimePicker, and other “complex” (made by different html parts) … Read more

jQuery Validation plugin in ASP.NET Web Forms

You can checkout the rules add function, but basically here’s what you can do: jQuery(function() { // You can specify some validation options here but not rules and messages jQuery(‘form’).validate(); // Add a custom class to your name mangled input and add rules like this jQuery(‘.username’).rules(‘add’, { required: true, messages: { required: ‘Some custom message … Read more

MVC3: make checkbox required via jQuery validate?

I’ve summarized here the correctly-working source code, which resulted from applying the accepted answer. Hope you find it useful. RequiredCheckbox.aspx <%@ Page Language=”C#” Inherits=”System.Web.Mvc.ViewPage<RegistrationViewModel>” %> <!DOCTYPE html> <html> <head runat=”server”> <title>RequiredCheckbox</title> <script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js” type=”text/javascript”></script> <script src=”https://ajax.microsoft.com/ajax/jQuery.Validate/1.7/jQuery.Validate.js” type=”text/javascript”></script> <script src=”https://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.validate.unobtrusive.js” type=”text/javascript”></script> <script type=”text/javascript” language=”javascript”> $.validator.unobtrusive.adapters.addBool(“mandatory”, “required”); </script> </head> <body> <div> <% // These directives can occur … Read more