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

  • Home
  • SEARCH
  • 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 show what htmlentities gives me, but it doesn't give
I am trying to understand if I really have any case for using git/mercurial.
I have been trying to find a really fast way to parse yyyy-mm-dd [hh:mm:ss]
In trying to solve the ajax back button problem I have found the Really
What i am really trying to achieve is to full control the active TabItem
The title may not really explain what I'm really trying to get at, couldn't
Really stuck on trying to write code to unzip a file or directory on
I am trying to write a really simple Outlook VSTO add in that checks
I am trying to understand difference between those two and really need a explanatory
My objective here is really simple -- I'm trying to set an NSString to

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.