Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9225407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:34:05+00:00 2026-06-18T04:34:05+00:00

I’m using the jQuery validation plugin to validate my forms, and I am also

  • 0

I’m using the jQuery validation plugin to validate my forms, and I am also using the addmethod function to create my own validation methods. This is how I set up jQuery Validator:

$(document).ready(function() {
    if ($("#validation_json").length > 0) {
        var validationJSON = JSON.parse(decodeURIComponent($("#validation_json").val()));
        $(".form-horizontal").validate({
            rules: validationJSON.rules,
            messages: validationJSON.messages
        });
    }
});

I have and input tag with the id validation_json, and the value set to a set of rules and messages for the jQuery validator plugin; these rules and messages are output server-side with the help of a form builder. The only issue is that whenever I add my own validation method, like so:

jQuery.validator.addMethod("uniqueemail", function(email) {
    return false; //just for testing
}, "This email is already in use");

jQuery validator will use this method before submitting the field to check if it is valid (in addition the the rules set above), however if one of the addMethod‘s validates to false, it will use the message for that item set above in the validate method, and not the message passed into addMethod. Does anyone know of a way that I could get it to display the message actually passed into the addMethod functions? Thanks!

UPDATE:

Here is a jsFiddle link showing the problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:34:06+00:00Added an answer on June 18, 2026 at 4:34 am

    There’s a problem with how you’ve set this up…

    $(document).ready(function() {
        if ($("#validation_json").length > 0) {
            var validationJSON = JSON.parse(decodeURIComponent($("#validation_json").val()));
            $(".form-horizontal").validate({
                rules: validationJSON.rules,
                messages: validationJSON.messages
            });
        }
    });
    

    .validate() is used to initialize the plugin once on DOM ready. You’ve put it inside a conditional statement, so the plugin is only initialized on the form if the if condition is met. Validation will fail to initialize at all other times. Use .valid() to trigger a validation test instead of re-initializing the plugin…

    $(document).ready(function() {
    
        $(".form-horizontal").validate({
            rules: validationJSON.rules,
            messages: validationJSON.messages,
            // any other options
        });
    
        if ($("#validation_json").length > 0) {
            var validationJSON = JSON.parse(decodeURIComponent($("#validation_json").val()));
            $(".form-horizontal").valid();  // trigger a validation test
        }
    
        jQuery.validator.addMethod("uniqueemail", function(email) {
            return false; //just for testing
        }, "This email is already in use");
    
    });
    

    Basic Demo: http://jsfiddle.net/AYvmg/

    The demo shows that your custom message from addMethod is working as expected.

    It’s possible to then dynamically change the custom message without another call to .validate() by using the .rules('add') method.

    $('#yourfield').rules('add', {
        messages: {
            uniqueemail: "this is a new message"
        }
    });
    

    Another Basic Demo: http://jsfiddle.net/5RnLM/

    This second demo works just like the first. Then when you click the #test button, the message for the rule is changed to something else. You could use this .rules('add') method to change your custom message whenever you need and from any other function.

    Otherwise, perhaps you can show the associated HTML and construct a jsFiddle demo to more clearly show the issue you’re having.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am reading a book about Javascript and jQuery and using one of the
I am using JSon response to parse title,date content and thumbnail images and place
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.