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 9012051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:53:56+00:00 2026-06-16T02:53:56+00:00

I need to create a custom rule for the Jquery Validation Plugin that checks

  • 0

I need to create a custom rule for the Jquery Validation Plugin that checks for one specific word.

In this case, the user must answer a question correctly by entering the word “cat” into the input field. The custom rule would need to define the answer as “cat”, I was thinking as a variable, and then check for it.

My failed attempt:

jQuery.validator.addMethod("answercheck", function(value, element) { 
  var password = string('hot');
  return value(password); 
}, "Type the correct answer");

and the setup:

rules: {
    input_answer{
        required: true,
        answercheck: true
    }

messages: {
    input_answer{
        required: "Answer the question",
        answercheck: "Your answer is incorrect"
    }

Any ideas?

  • 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-16T02:53:57+00:00Added an answer on June 16, 2026 at 2:53 am

    As others have stated, this is not a secure method since anyone could see/manipulate the JavaScript and easily bypass it.

    However, to simply answer your question, here’s how it’s done. (It’s also a good learning exercise about using addMethod)…

    jQuery.validator.addMethod('answercheck', function (value, element) { 
        return this.optional(element) || /^\bcat\b$/.test(value);
    }, "Type the correct answer");
    

    And you also wouldn’t need to specify a message for answercheck below, because it’s already defined above within the method itself. (You were also missing some braces {, colons :, and a comma , in this code.)

    rules: {
        input_answer: { // <- missing colon after input_answer
            required: true,
            answercheck: true
         }
    }, // <- missing brace & comma
    messages: {
        input_answer: { // <- missing colon after input_answer
            required: "Answer the question"
            //, answercheck: "Your answer is incorrect"  // not needed, specified in method
        } 
    } // <- missing brace and maybe a comma depending on what follows
    

    Working jsFiddle DEMO:

    http://jsfiddle.net/ht8Lu/


    As per the documentation, you’ll need to construct your own custom method.

    Add a custom validation method. It must consist of a name (must be a
    legal javascript identifier), a javascript based function and a
    default string message.

    Arguments:

    name; String The name of the method, used to identify and referencing it, must be a valid javascript identifier

    method; Callback The actual method implementation, returning true if an element is valid. First argument: Current value. Second
    argument: Validated element. Third argument: Parameters.

    message (Optional); String, Function The default message to display for this method. Can be a function created by
    jQuery.validator.format(value). When undefined, an already existing
    message is used (handy for localization), otherwise the field-specific
    messages have to be defined.

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

Sidebar

Related Questions

I need to create a custom TextBox control that allows user input HTML tags.
I have a custom validation rule on a model that says the user can't
I need to create a rule that rewrites an URL to a new one
I need to create a custom user interface using extJS/JSP which will allow me
I've got a FxCop custom rule and I need to be able to create
I need to create a custom Component with JSF 2.0 (not composite component), that
I need to create one textfield custom components which accepts only credit card number
I'm trying to create a custom validation rule for when a checkbox is checked,
I need to be able to create custom calendars that can omit certain holidays
I need to create a custom attribute that is applicable only for non static

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.