PHP: Native e-mail and URL validation

Published by Lennart Van Vaerenbergh on August 30, 2019

A clean and easy way to validate an e-mail address or URL in PHP:
 
$validEmail = (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
$validUrl = (bool) filter_var('http://example.com', FILTER_VALIDATE_URL);

More information on this can be found on:
https://www.php.net/manual/en/function.filter-var.php
https://www.php.net/manual/en/filter.filters.flags.php

Add new comment

(If you're a human, don't change the following field)
Your first name.
(If you're a human, don't change the following field)
Your first name.
CAPTCHA
This challenge is for testing whether or not you are a human visitor and to prevent automated spam submissions.