Email validation within a form in PHPIn an input field we can verify the email address entered is in correct format or not using PHP eregi function. This is a part of php form validation we do for other entries to check proper formatted data is entered by the user or not. You can enter any email address and check it is a valid address or not. Please not that we are not checking the validation or existence of the URL or the service provider. We are only checking / validating the format of the email address. This code can be used as a part of the other entered data validation used. You can read the php form validation by visiting the tutorial here. Here is the demo of the email validation. Test this validation by entering any formatted email address. You will get a message based on the result of validation.
How to receive email addressVisitors enter their email address in a textbox kept inside a web form.
From a web form we will get email address either by GET or POST method to the processing script. For ready reference here are two ways to get the email address from a web form.
You can read more on form handling by PHP here.
Here is the code of this validation in PHP.
eregi is DEPRECATED in PHP 5.3.0 and removed in PHP 7.0.0
Better use preg_match
Checking presence of @ and .Minimum requirement of any email address is presence of @ and one dot ( . ) . Here we can check for the presence of these two conditions and clear or validated the variable in the presence of these two chars. Note that many complex conditions were this checking will fail but to maintain simplicity this can be used.
Using filter in PHPPHP has built in filter and it is enabled for PHP version 5.2.0 onwards. By using filter we can check various other type of data including email address.
This article is written by plus2net.com team.
| ▼ Web Forms & handling data in PHP