jQuery Username Availability Validation
It is common operation on each `sign up` or the `registration` process.
Whenever we create or add new user into the system, we need to add a common identifier for each user and that becomes username, it can be email address or just a string.
Having said that while doing this process we need to validate the username and validation is actually check whether particular username is available to user or not.
Let’s make it simple to understand, in programming words `check if is there any existing username is present in the database table`
In this tutorial I am going to explain each aspect along with the source code. let’s get started step by step:
Step 1: Database Setup
Create MySQL database table to store users details. (if you have already created that’s fine! just match your field name with the source code) and have few dummy records record entries to test.
CREATE TABLE `users` ( `id` INT( 11 ) NOT NULL AUTO_INCREMENT , `username` VARCHAR( 50 ) NOT NULL , PRIMARY KEY ( `id` ) ) ENGINE = MYISAM ;
`SQL Dummy Records:`
INSERT INTO `users` ( `id` , `username` ) VALUES ( NULL , 'user1' ), ( NULL , 'user2' );
Step 2: Start Programming
Create MySql Database Connection File:
2.1 Create DB connection file `db_connection.php` and use following code and update the connection variable settings according to your system settings.
Username Availability Check:
2.2 Create PHP file to check username : username_check.php
Sample Registration Form to Test Username:
2.4 Create and open script.js file and write following code, to check username. : `script.js`
2.5 Review folder structure:
Output (error message ):
Output (success message ):
Your done, run your code to checkout or you can download the source code from below link: