Friday, February 14, 2014

jQuery Username Availability check.

jQuery Username Availability check.

Hi in this lessons i am going to teach you how to check that a username is available with jQuery. This is very useful for developer as well as the users because they see a nice UI
jQuery username Availability Check.

Download Script View Demo 


in index.php page their is a simple input field were user put their username and that data is send to a php file this is done is real time using jQuery .keyup(function(){ }); and in the ajax request we have give a response variable in the success object this variable get the response text from the username.php file

<form method="post">
 <input type="text" id="username" placeholder="username">
 <span id="feedback"></span>
<script src="//"></script>
<script type="text/javascript">
$(document).ready(function() {
 $('#username').keyup(function() {
  var username = $(this).val();
  //send the data to a username.php file
   url: './username.php',
   type: 'POST',
   data: {username:username},
   beforeSend: function(){
   //get the response text from the username.php file
   success: function(response){


In username.php file the username is coming from the input filed which is in the index.php file. In username.php we are check that the username already in the database or not and outputing the result.

 //connect to the database

  $username = mysql_real_escape_string($_POST['username']);
  $q = mysql_query("SELECT * FROM users WHERE username='$username'");
  $num = mysql_num_rows($q);
  if($num >= 1){
   echo "<span style='color:red'>".$username." Not Available</span>";
   echo "<span style='color:green'>".$username." Available</span>";