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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:57:24+00:00 2026-05-18T23:57:24+00:00

I am trying to use this plugin: http://docs.jquery.com/Plugins/Validation Where #user_new is the id for

  • 0

I am trying to use this plugin: http://docs.jquery.com/Plugins/Validation

Where #user_new is the id for my form, this is what my code looks like:

$('#user_new').validate({
    rules: {
        user[username]: "required",
        user[email]: {
            required: true,
            email: true
        }
    },
    messages: {
        user[username]: "Please specify your name",
        user[email]: {
            required: "We need your email address to contact you",
            email: "Your email address must be in the format of name@domain.com"
        }
    }
})

Where these are how my input fields look when the page is rendered (generated by Rails):

<input class="clearField curved" id="user_f_name" name="user[f_name]" size="30" type="text" value="First Name" /><br /> 
        <input class="clearField curved" id="user_l_name" name="user[l_name]" size="30" type="text" value="Last Name" /><br /> 
        <input class="clearField curved" id="user_username" name="user[username]" size="30" type="text" value="Username" /><br /> 
        <input class="clearField curved" id="user_password" name="user[password]" size="30" type="password" value="Password" /><br /> 
        <input class="clearField curved" id="user_password_confirmation" name="user[password_confirmation]" size="30" type="password" value="Password" /><br /> 
        <input class="clearField curved" id="user_email" name="user[email]" size="30" type="text" value="Email Address" /><br /> 

I was just trying to validate username & email first. Then take it from there.

For the life of me, I can’t figure out how to specify the syntax and the rules for working with this plugin.

Help!

Edit1: Here is the HTML output for the form tag:

<form accept-charset="UTF-8" action="/users/login" class="user_new" id="user_new" method="post">

As for the question about debug, when I include it like so:

$('#user_new').validate({
    debug: true,
    rules: {
        user_username: "required",
        user_email: {
            required: true,
            email: true
        }
    },
    messages: {
        user_username: "Please specify your name",
        user_email: {
            required: "We need your email address to contact you",
            email: "Your email address must be in the format of name@domain.com"
        }
    }
});

I see nothing in my JS console.

Edit2: When I clear my login fields of data and press submit, it won’t submit. Not sure if this is something to do with the validate() function actually working. But I see no messages pop-up or anything like that.

Edit3: It seems that the problem might be a disconnect between the ID & name fields being named differently. However, Rails assigns the name and ID to both fields – so not sure how to fix this.

Edit4: I found a solution. I added it to a comment under the chosen answer.

  • 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-05-18T23:57:25+00:00Added an answer on May 18, 2026 at 11:57 pm

    i think its because the value of the “name” attribute in the form (the input tag) does not match the jquery validate option

    $('#user_new').validate({
        debug: true,
        rules: {
            user_username: "required", // should be: "user[username]"
            user_email: { // should be: "user[email]"
                required: true,
                email: true
            }
        },
        messages: {
            user_username: "Please specify your name", // should be: "user[username]"
            user_email: { // should be: "user[email]"
                required: "We need your email address to contact you",
                email: "Your email address must be in the format of name@domain.com"
            }
        }
    });
    

    Edit: take a look at this question, i think he has the same problem as you are jquery.validate in cakePHP

    Edit2: to edit the way it display, put a container right after your input tag, let say

    <div id="username_error"></div>//for username error message
    

    add this codes:

    $('#user_new').validate({
        debug: true,
        rules: {
            //rules
        },
        messages: {
            //messages
        },
        errorPlacement: function(error, element) {
            if ( element.is(":radio") )
                error.appendTo( element.parent().next());//if its a radio button
            else if ( element.is(":checkbox") )
                error.appendTo ( element.next() );//if its a radio button
            else
                error.appendTo( element.parent().next() );
        },//these lines of codes basically telling the jquery.validate plug-in to look for an element after
    });
    

    and then apply some css to tidy things up

    <style>
    #username_error{
       //a little something something
    }
    </style>
    

    or you can always check the documentation for further modifications

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

Sidebar

Related Questions

i am trying to use this code to bind my asp.net menu control to
I'm trying to use this code to replace spaces with _, it works for
I'm trying to use Spring IoC with an interface like this: public interface ISimpleService<T>
I am trying to use JQuery in my ASP.Net 2.0 website in this scenario:
I'm trying to use this layout with two 50% column width instead. But it
I am trying to use this in my page class. I only just started
I'm trying to use the this keyword in a static method, but the compiler
I'm trying to use the freeware Multiple Find And Replace 1.00 suggested in this
I'm trying to use slime from CVS (2009-01-05) but keep getting this error: LOAD:
I'm trying to use System.DirectoryServices in a web site project and I'm getting this

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.