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

Validate Dynamically Added Input fields

You should have ‘name’ attribute for your inputs. You need to add the rules dynamically, one option is to add them when the form submits. And here is my solution that I’ve tested and it works: <script type=”text/javascript”> $(document).ready(function() { var numberIncr = 1; // used to increment the name for the inputs function addInput() … Read more

Using JQuery Validate Plugin to validate multiple form fields with identical names

Instead of changing the source file jquery.validation you can simply override the function you need to edit only in the pages that requires it. An example would be: $.validator.prototype.checkForm = function() { //overriden in a specific page this.prepareForm(); for (var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++) { if (this.findByName(elements[i].name).length !== undefined … Read more

Jquery Validate custom error message location

What you should use is the errorLabelContainer jQuery(function($) { var validator = $(‘#form’).validate({ rules: { first: { required: true }, second: { required: true } }, messages: {}, errorElement : ‘div’, errorLabelContainer: ‘.errorTxt’ }); }); .errorTxt{ border: 1px solid red; min-height: 20px; } <script type=”text/javascript” src=”http://code.jquery.com/jquery-1.11.1.js”></script> <script type=”text/javascript” src=”http://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.12.0/jquery.validate.js”></script> <script type=”text/javascript” src=”http://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.12.0/additional-methods.js”></script> <form id=”form” method=”post” … Read more