Email validation within a form in PHP

Related concepts: HTML forms · PHP form validation

Validate an email address

For normal server-side email-format validation, FILTER_VALIDATE_EMAIL is clearer and more maintainable than a custom regular expression. Format validation does not prove that the mailbox exists.

$email = trim($_POST['email'] ?? '');

if (filter_var($email, FILTER_VALIDATE_EMAIL) !== false) {
    echo 'Valid email format';
} else {
    echo 'Invalid email format';
}
Enter any email address

We check the address format only; this does not prove the mailbox exists.

Email Validation In an input field we can verify whether an email address has a valid format using PHP's built-in filter API. 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.
This code can be used as a part of the other entered data validation used. You can read the php form validation here.

The HTML FORM for user to input email

<form method=post action=''>Enter any email address 
<input type=text name=email value=$email>
<input type=submit value=Check>
<input type=hidden value=test name=todo>
</form>

How to receive email address

Visitors 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.
$email=$_GET['email']; // GET method 
$email=$_POST['email']; // POST method  

Using FILTER_VALIDATE_EMAIL

Use filter_var($email, FILTER_VALIDATE_EMAIL) for normal server-side email-format validation instead of maintaining a custom regular expression.

PHP's filter extension provides built-in validators for common input types, including email addresses.
FILTER_VALIDATE_EMAIL Email validation using Ajax & PHP
PHP Form


Subscribe to our YouTube Channel here



plus2net.com







good

22-05-2013

its interestiing..!!
albusaidy

16-11-2014

worked great for me.. I love the fact that the page I was working on stayed on screen, and script showed where change needed to be made. Awesome
Is there a way to make sure people do not enter www. in front of their email, it happens often.
John S

17-04-2019

Hello,
eregi() is deprecated as of PHP 5.3
Thanks.




PHP video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer