Username availability check using PHP and jQuery

It’s always good to check the username or email for availability before submission. So the user can check it instantly and helps them to enter the valid one.

This can be done using PHP and jQuery. Just a little code will do the rest.

Script used:

<script src="" type="text/javascript"></script>
<script type="text/javascript">
function checkUserName(usercheck)
	$('#usercheck').html('<img src="images/ajax-loader.gif" />');
	$.post("checkuser.php", {user_name: usercheck} , function(data)
			   if (data != '' || data != undefined || data != null) 

The CSS used:

font-family:"Trebuchet Ms";
color: #FF0000;
color: #33CC00;

The HTML page:

<div style="padding:100px 0px  50px 10px;">
Username : <input type="text" name="username" id="username" onblur="checkUserName(this.value)" /> 
<span id="usercheck" style="padding-left:10px; ; vertical-align: middle;"></span>

The PHP (processing) page:

$arr_user=array("itechroom", "trialuser");
{echo '<span class="error">Username already exists.</span>';exit;}
else if(strlen($username) < 6 || strlen($username) > 15){echo '<span class="error">Username must be 6 to 15 characters</span>';}
else if (preg_match("/^[a-zA-Z1-9]+$/", $username)) 
       echo '<span class="success">Username is available.</span>';
      echo '<span class="error">Use alphanumeric characters only.</span>';

View Demo Download

Be Sociable, Share!
You can leave a response, or trackback from your own site.

7 Responses to “Username availability check using PHP and jQuery”

  1. [...] have seen checking username availability using jQuery in earlier post. Here is a slight modification on showing of error/success message. [...]

  2. [...] 4. בדיקת זמינות משתמש באמצעות PHP ו-jQuery [...]

  3. [...] Username availability check using PHP and jQuery [...]

  4. [...] 7) Username Availability Check Using PHP and jQuery [...]

  5. Maxim says:

    Please Modify the above code to prevent submission if username is not available.

Leave a Reply

CommentLuv badge

Powered by WordPress