• We just launched and are currently in beta. Join us as we build and grow the community.

How To Check Username Availability in Sign Up Form

josesilva

System Reliability Specialist
J Rep
0
0
0
Rep
0
J Vouches
0
0
0
Vouches
0
Posts
121
Likes
180
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 500 XP
Check Username Availability in Log In Form

In this tutorial, we are going to learn on How To Check Username Availability in Sign Up Form.

This tutorial will show you how to check the username availability in sign up form using jQuery in PHP. This program will sure the uniqueness of username or email address.

HTML Form Field

  1. <form

    >
  2. <b

    style

    =

    "color:blue;"

    >

    Username</

    b

    ><br

    >
  3. <input

    id

    =

    "username"

    type

    =

    "text"

    name

    =

    "username"

    onkeyup

    =

    "twitter.updateUrl(this.value)"

    placeholder=

    "Username"

    style

    =

    "float:left; border-radius:3px; padding:5px;"

    /

    ><br

    >
  4. <div

    id

    =

    "status"

    style

    =

    "float:left; margin-top:-20px;"

    ></

    div

    >
  5. <br

    >
  6. <b

    style

    =

    "color:blue;"

    >

    Password</

    b

    ><br

    >
  7. <input

    type

    =

    "text"

    name

    =

    "password"

    placeholder=

    "Password"

    style

    =

    "border-radius:3px; padding:5px; float:left; clear:both;"

    /

    ><br

    ><br

    >
  8. <input

    type

    =

    "button"

    name

    =

    "submit"

    value

    =

    "Register"

    style

    =

    "padding:5px;"

    >
  9. </

    form

    >

JavaScript Script

  1. <

    script type=

    "text/javascript"

    >
  2. pic1 =

    new

    Image(

    16

    ,

    16

    )

    ;
  3. pic1.src

    =

    "loader.gif"

    ;

  4. $(

    document)

    .ready

    (

    function

    (

    )

    {

  5. $(

    "#username"

    )

    .change

    (

    function

    (

    )

    {

  6. var

    usr =

    $(

    "#username"

    )

    .val

    (

    )

    ;

  7. if

    (

    usr.length

    >=

    3

    )
  8. {
  9. $(

    "#status"

    )

    .html

    (

    '<img src="loader.gif" align="absmiddle">&nbsp;Checking availability...'

    )

    ;

  10. $.ajax

    (

    {
  11. type:

    "POST"

    ,
  12. url:

    "check.php"

    ,
  13. data:

    "username="

    +

    usr,
  14. success:

    function

    (

    msg)

    {

  15. $(

    "#status"

    )

    .ajaxComplete

    (

    function

    (

    event,

    request,

    settings)

    {

  16. if

    (

    msg ==

    'OK'

    )
  17. {
  18. $(

    "#username"

    )

    .removeClass

    (

    'object_error'

    )

    ;

    // if necessary
  19. $(

    "#username"

    )

    .addClass

    (

    "object_ok"

    )

    ;
  20. $(

    this

    )

    .html

    (

    '&nbsp;<img src="check.jpg" style="width:25px;" align="absmiddle"> <font color="Green" style="font-size:14px;"> Available! </font> '

    )

    ;
  21. }
  22. else
  23. {
  24. $(

    "#username"

    )

    .removeClass

    (

    'object_ok'

    )

    ;

    // if necessary
  25. $(

    "#username"

    )

    .addClass

    (

    "object_error"

    )

    ;
  26. $(

    this

    )

    .html

    (

    msg)

    ;
  27. }

  28. }

    )

    ;

  29. }

  30. }

    )

    ;

  31. }
  32. else
  33. {
  34. $(

    "#status"

    )

    .html

    (

    '<font color="red" style="font-size:14px; margin-left:5px;">The username should have at least <strong>3</strong> characters.</font>'

    )

    ;
  35. $(

    "#username"

    )

    .removeClass

    (

    'object_ok'

    )

    ;

    // if necessary
  36. $(

    "#username"

    )

    .addClass

    (

    "object_error"

    )

    ;
  37. }

  38. }

    )

    ;

  39. }

    )

    ;

  40. //-->
  41. </

    script>

This is the result.

1_106.png


Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,158

323,328

323,337

Top