Take the 2-minute tour ×

I am using jquery form validation plugin http://docs.jquery.com/Plugins/Validation/validate

How can I set a callback which will be get called before calling it's validation function ? I want to trim the values and some pre-validation.

share|improve this question
Callback before actual validation? or before submit? –  charlietfl Mar 5 '12 at 14:26
actual validation. –  Vivek Goel Mar 5 '12 at 14:32

2 Answers 2

up vote 2 down vote accepted

addMethod() lets you create own validation method instead of using predfined ones. Within method do the processing necessary.

For example for trimming you could trim the value, and replace it in field...and test against the trimmmed value. Otherwise using change event handlers on fields would likely help also


share|improve this answer

Putting @charlietfl's answer into practice, this is what I've done (in case it's useful to anyone):

  function(value, element, param) {
    return true;

$(document).ready(function() {
    rules: {
      name: {
        trim: true,
        required: true
      email: {
        trim: true,
        email: true

The first rule trims the value, then you can add additional rules like required or email.

share|improve this answer

Your Answer


