I’m writting a small contact form from scratch and I needed a quick and dirty way to validate an email address with PHP
I’ve googled to find some examples and I found many examples for completing the task, however in order to validate the email address I eventually ended up with the following PHP code:
if ( preg_match( "/^[-w.]+@([A-z0-9][-A-z0-9]+.)+[A-z]{2,4}$/", $email ) )
{
# Do some processing here - input if valid
}
else
{
echo 'Incorrect email dying';
exit(1);
}
Now just pass the input $email variable from your form to the if condition and modify according to your needs.
More helpful Articles
Tags: How to validate a form email address with PHP / PHP Validate Email address