0

I am using jquery validator for client side as well as server side validation.

But i want to show error of one form filed with another form field.

Can anyone suggest how to acheive that?

I am using following validator class.

http://jquery-validation-php-plugin.googlecode.com/svn-history/r6/trunk/Validator.class.php

Thanks in advance.

user519846
  • 999
  • 7
  • 15
  • 26

2 Answers2

0

You can create a new rule in jquery validation plugin. Check this link jquery-validate - addMethod - how to apply custom rule referencing two text boxes?

In this rule you can check the form field and accordingly return the value of rule.

Or otherwise you can change the rule for a field. Suppose you got a field 'firstName', so you can add your custom code like this

firstName:
{
   required: function(element)
   {
      // here you can add your custom code
   }
}
Community
  • 1
  • 1
Mahesh KP
  • 6,248
  • 13
  • 50
  • 71
0

You can use addMethod rule for this customized validation. For Example, if you have a form id="mainForm" with state lists in the drop down. Suppose your drop down is having id ="drpState" then, write like this

HTML
-------
<select>
  <option value="-1">- Select -</option>
  <option value="1">Aus</option>
  <option value="2">Mogs</option>
  <option value="3">Swut</option>
 </select>

Jquery
-------
jQuery(document).ready(function () {
$.validator.addMethod("selectState", function (value, element) {
        return this.optional(element) || (value.indexOf('-1'));
    }, "Please select state");

    $("#mainForm").validate({
       rules: {drpState:{selectState:true},
  });
});

Please refer for more : http://ssthil.blogspot.in/2012/06/jquery-validate-multiple-fields-with.html Let me know your feedback