Email validation Using Ajax & PHPYou can see how email validation is done by using regular expression in PHP. We will further extend this validation by using PHP & Ajax. As you know for validation purpose we will be using the same PHP code so it is better you try to understand the PHP code by reading the email validation tutorial. We will discuss the Ajax part here only.
Usually within a form email field is required along with some other fields like name, address etc so we have kept here two other fields name and city name along with email entry field. While filling the data we will first fill name and then email and then city name. When we finish entering the email address we will exit the email address to next field, at that time the validation code written in PHP of email will be executed. So we have used onBlur event handler of email field to trigger the validation code using Ajax. Read this code line.
As you have seen we have passed the email data as entered by user to the Ajax function and then through XMLHttpRequest we will pass this email data to our php code kept at server inside a PHP file. The validation code in PHP is same as our email validation code. The output of this validation is displayed at the form here. See the demo bellow.
The HTML code to display the form ( as in the above demo ) is here
Now the code kept within email-ajax.php file is here, this is same code as explained at email validation tutorial
The above code in email-ajax.php file can be replaced by this code if you are using email filter function .
Be the first to post comment on this article :