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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:08:22+00:00 2026-05-16T11:08:22+00:00

I really was trying to avoid asking this question. I have seen quite a

  • 0

I really was trying to avoid asking this question. I have seen quite a few posts on SO regarding this plugin but they still didn’t quite get it for me. Right now I have a new account registration form and I’m trying to write a custom method for validating a unique username. I would like to think that the following should work:

$.validator.addMethod(
        "uniqueUsername", 
        function(value, element) {
            $.post(
                "http://" + location.host + "/scripts/ajax/check_username.php",
                {
                    username: value
                },
                function(response) {
                    if(response == 'true') {
                        return true;
                    } else {
                        return false;
                    }
                }
            );
        },
        "This username is already taken."
    );

Unfortunately it seems like the plugin moves on regardless of the callback function. I found someone suggest doing something like the following:

var result = false;
    $.validator.addMethod(
        "uniqueUsername", 
        function(value, element) {
            $.post(
                "http://" + location.host + "/scripts/ajax/check_username.php",
                {
                    username: value
                },
                function(response) {
                    if(response == 'true') {
                        result = true;
                    } else {
                        result = false;
                    }
                }
            );
            return result;
        },
        "This username is already taken."
    );

But it seems to have a delay since it stores the value, then on the next event will set whatever the value is. What do you guys recommend?

  • 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-16T11:08:23+00:00Added an answer on May 16, 2026 at 11:08 am

    Since this is an asynchronous check, there needs to be more around it (you can’t return a value from a function like this, it’ll always be false in your case). The built-in method is remote, used like this:

    $("form").validate({
      rules: {
        username: {
          remote: {
            url: "http://" + location.host + "/scripts/ajax/check_username.php",
            type: "post"
          }
        }
      }  
    });
    

    This will POST a username: valueofElement since the rule is for the element named username. Your server-side script should return true if the validation should pass, false otherwise…so false if the user name is already taken.

    You can read more about the remote option here, including how to pass additional data arguments if needed.

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

Sidebar

Related Questions

i am really trying to do this but i am failing to find a
(This question is not about programming, but about how to avoid doing any programming.
I was really trying to avoid making the title too ambiguous, but I wasn't
I searched SO and found this question , but it's not quite what I'm
I'm really trying to like generics, but so far the trouble they've caused outweighs
I am really trying to show what htmlentities gives me, but it doesn't give
I'm really trying to understand the difference between OpenID and OAuth? Maybe they're two
I'm really trying to switch to emacs, but learning to setup the environment is
Really, really trying to find a plugin that gives adds functionality to the image-resize
I'm sure there's a really easy way of doing this. I'm trying to take

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.