Live Field Check

Live username availability check while you type. When there is a pause of 500 milliseconds the username will be checked against the database.
The username choice will be reserved temporarily for 6 minutes, temporary blocking the username from other users.
If the username is not selected, it will be freed for others to reserve.

 This example is using jQuery, PHP Data Objects and MySQL, of course you can use a different database if you wish.

Username  

In this example I am using a delayCall function I have written, it can support multiple fields needed a delay:

function delayCall(obj,ms,callback){
    return $(obj).each(function(){
        if ( typeof this.timer == 'undefined' ){
            // Define an array to keep track of all fields/objects needed delays
            // This is in order to make this a multiple delay handling function
            this.timer = new Array();
        }
        var obj = this;
        if (this.timer[obj.id]){
            // in case the timeout have not been reached and we get a new keystroke, we reset the timer
            clearTimeout(this.timer[obj.id]);
            delete(this.timer[obj.id]);
        }

        this.timer[obj.id] = setTimeout(function(){
        callback(obj);}, ms);
    });
};

We use it this way basically:

$("#username").on("keyup",function(){delayCall($(this),500,fieldKeyup);});
 

You can download the complete example here.

What you need to have this sample on your site:

  1. username.html - This HTML page.
  2. username.sql - Database tables
  3. username.php - The script that manages the username reservation and temporary blocking.
  4. username.js - This jQuery script communicates with username.php on the server.