SQL PHP HTML ASP JavaScript articles and free scripts to download
 
 

Email validation within a form in PHP

In 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.
Enter any email address


Here is the code of this validation in PHP.
if(isset($todo) and $todo=="test"){
if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
echo "<center><font face='Verdana' size='2' color=red>Invalid email</font></center>";
}else{echo "<center><font face='Verdana' size='2' color=green>Valid Email</font></center>";}
}

Discuss this tutorial at forum


Further readings
All form components validation with post back and data locking
Checkbox
How to retain form data if validation fails?
How to retain data of a text box after submitting
Retaining status of a check box
Updating checkbox value from & to a table record.
Retaining selected data of a period button of a form
Retaining selected data of a drop down list box of a form
Validating Date: Checking if date exist
Email address validation in a form
PHP Form Validation
is_numeric to check numeric numbers
ctype_alnum to check alphanumeric characters data
ctype_alpha to check alphabetic characters data
How to take care of form & query string variables if Register global is OFF?














 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorial Index
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
PHP Tutorials
Date & Time
Array
String Functions
Math Functions
Form Handling
File Handling
Comment Posting
Content Management
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.