What's the best practice for make username check like Twitter ?

Posted by Space Cracker on Stack Overflow See other posts from Stack Overflow or by Space Cracker
Published on 2010-05-11T08:31:46Z Indexed on 2010/05/11 8:34 UTC
Read the original article Hit count: 187

Filed under:
|
|

I develop registration form and it have username field, and it's required to be like twitter username check ( real time check ) .. i already develop as in every textbox key up I use jquery to pass textbox.Text to page that return if is username exist or not as following code :

function Check() {

        var userName = $('#<%= TextBox1.ClientID %>').val();
        if (userName.length < 3) {
            $('#checkUserNameDIV').html("user name must be between 3 and 20");
            return;
        }
        $('#checkUserNameDIV').html('<img src="loader.gif" />');
        //setTimeout("CheckExistance('" + userName + "')", 5000);
        CheckExistance(userName);

    }
    function CheckExistance(userName) {
        $.get(
            "JQueryPage.aspx", { name: userName },
             function(result) {
                 var msg = "";
                 if (result == "1")
                     msg = "Not Exist " + '<img src="unOK.gif" />';
                 else if (result == "0")
                     msg = "Exist" ;
                 else if (result == "error")
                     msg = "Error , try again";

                 $('#checkUserNameDIV').html(msg);
             }
        );
    }

but i don't know if is it the best way to do that ? specially i do check every keyup ..

is there any design pattern for this problem > or nay good practice for doing that ?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about twitter