Download:jquey.min.js
index.php:
index.php:
<html> <style> .error{color: #FF0000;font-size:14px;} .success{color: #33CC00; font-size:14px;} #whole{ border:1px solid #F00; width:34%; margin:10%;padding:12px; margin-top:100px; background-color:#000; color:#FFF;} </style> <script src="jquery.min.js" 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) { $('#usercheck').html(data); } }); } </script> </head> <body> <div style="width:38%; margin:10%;padding:12px; margin-top:100px; background-color:#000; color:#FFF;"> <div style="padding:20px 0px 10px 10px;"> Username : <input type="text" name="username" id="username" onblur="checkUserName(this.value)" /> <span id="usercheck" style="padding-left:10px; ; vertical-align: middle;"></span> </div> <div style="padding:15px 0px 20px 10px;"> Password : <input type="password" name="pwd" /> </div> </div> </body> </html>checkuser.php:
<?php $arr_user=array("itechroom", "trialuser"); $username=$_POST['user_name']; if(in_array($username,$arr_user)) {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>'; } else { echo '<span class="error">Use alphanumeric characters only.</span>'; } ?>
No comments:
Post a Comment