1

I have the following code and it doesn't work with the custom messages, but it works with the default message. Jquery validation custom message is not working for array based field name.

$("#signup").validate({

ignore: "",
rules: {
"data[email]": {
    //cardCVC: true,
    required: true,
    email:true
},
"data[password]": {
    required: true,
    minlength: 5
},
 "data[cpassword]":{
    required:true 
},
"data[captcha]":{
    required:true
}, 
// Specify the validation error messages
messages: {

   'data[email]':{
       required: "Please enter a valid email address"
    }
},

submitHandler: function(form) {
    form.submit();
}


}

});



{{Form::open(array('url'=>'signup','method'=>'post','id'=>'signup','novalidate'=>"novalidate"))}}

    <label for="login_email" class="required">Email address</label>
    <input type="email" name="data[email]" id="email">

Could anyone help me to sort out the issue? Thanks AZ

Sparky
  • 98,165
  • 25
  • 199
  • 285
jai
  • 547
  • 7
  • 20
  • Can you clarify the problem please ? What do you mean by `it doesn't working the custom messages but it works with default message.` ? what is the working code, and the not-working code ? What are the errors of the non-working code ? – Random May 13 '15 at 12:48
  • the default message means ex: "This field is required." .The custom message means "Please enter a valid email address". Currently the above code works with the default message – jai May 13 '15 at 12:54
  • Please check once what i given as an answer below. – Alive to die - Anant May 13 '15 at 13:13
  • What does PHP have to do with anything here? Please do not tag-spam. Edited. Thanks. – Sparky May 16 '15 at 15:24

1 Answers1

1

Actually you are not following the proper format of jquery validator custom message.Please do in following manner: --

rules: {
    'data[email]': {
        //cardCVC: true,
        required: true,
        email:true
    },
    "data[password]": {
        required: true,
        minlength: 5
    }
  ,    "data[cpassword]":{

        required:true

    },
    "data[captcha]":{
        required:true
    }
},
messages: {

       'data[email]':{
           required: "Please enter a valid email address"
        }
 },
    submitHandler: function(form) {
        form.submit();
    }

});

Note:- for reference :- http://runnable.com/UkmCKF6ekb0tAAC-/how-to-use-jquery-validation-custom-messages-and-placement

If you want to change directly it's default messages with costume messages:- jQuery validation: change default error message

Community
  • 1
  • 1
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98