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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:28:00+00:00 2026-05-27T22:28:00+00:00

I am trying to check the user username when typing it in the signup

  • 0

I am trying to check the user username when typing it in the signup form and I have created the following function:

function validateSignupEmail(input){
    if (input == ""){
        return "Please enter your usernane.";
    }else if (input.length > 20){
        return "Your username cant exceed 20 characters.";
    }else{
        var type = "username_check";
        $.ajax({
            type: "POST",
            url: www+"signup/validate",
            dataType: 'json',
            data: {
                type : type,
                input : input
            },
            success: function(data) {
                return data.response;
            }
        });
    }
}

Inside the signup controller I have the following function called validate()

function validate(){
    $type = isset($_POST["type"]) ? $_POST["type"] : "";
    $input = isset($_POST["input"]) ? $_POST["input"] : "";

    if ($type == "username_check"){
        echo json_encode(array('response' => 'username available'));
    }else{
        return false;
    }
}

Also I have the following code which shows what the username status in a div:

$("#signup_page form input[type='text']#username").keyup(function(){
    var text = validateSignupEmail($(this).val());
    console.log('text => '+text);
    $(".signup_ajax_live_messages").find(".username_check").text(text);
})

The thing is that I can’t return the AJAX response inside the success: function(){}

Thanks.

  • 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-27T22:28:01+00:00Added an answer on May 27, 2026 at 10:28 pm

    Welcome to the wonderful world of async, where you have to wait for the AJAX call to complete before processing the response.

    Here’s how you would process the response in your callback:

    $("#signup_page form input[type='text']#username").keyup(function(){
        validateSignupEmail($(this).val());
    });
    
    function validateSignupEmail(input){
        if (input == ""){
            return "Please enter your usernane.";
        }else if (input.length > 20){
            return "Your username cant exceed 20 characters.";
        }else{
            var type = "username_check";
            $.ajax({
                type: "POST",
                url: www+"signup/validate",
                dataType: 'json',
                data: {
                    type : type,
                    input : input
                },
                success: function(data) {
                    $(".signup_ajax_live_messages").find(".username_check").text(data.response);
                }
            });
        }
    }
    

    On a side note: Are you sure you want to make a new AJAX request on every single keystroke?


    If you want to only check after the user has paused typing, use setTimeout:

    var timer;
    $("#signup_page form input[type='text']#username").keyup(function(){
        var text = $(this).text();
        timer && clearTimeout(timer);
        timer = setTimeout(function(){
            validateSignupEmail(text);
        }, 400); // <-- this is the amount of milliseconds for the user to pause before making the AJAX call
    });
    

    Here’s an example: http://jsfiddle.net/dMhdD/

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

Sidebar

Related Questions

I am trying to build custom django form for changing username and user email
I am trying to make a form which would check if an username is
I'm trying to user jQuery Validation plugin to validate a signup form, but I
I am trying to check if a user is a member of an Active
Is it best to check for a null User when trying to access UserID
I'm trying to programmatically intercept and cancel a user's attempt to check out a
i am trying to check my user name is if its available to register
I have created a website from File->new-> Web Site. i am trying to go
I am trying to check if the user belongs to someone's friendlist from the
I have a working PHP registration form that goes through $_POST[] requests to check

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.