Last Updated: February 25, 2016
·
686
· rogeriolino

PHP simple e-mail, URL and IP validation

e-Mail

echo filter_var('email@domain.com', FILTER_VALIDATE_EMAIL); // email@domain.com
echo filter_var('domain.com', FILTER_VALIDATE_EMAIL); // false

URL

echo filter_var('http://rogeriolino.com', FILTER_VALIDATE_URL); // http://rogeriolino.com
echo filter_var('rogeriolino.com', FILTER_VALIDATE_URL); // false

IP

echo filter_var('127.0.0.1', FILTER_VALIDATE_IP); // 127.0.0.1
echo filter_var('127.0.1', FILTER_VALIDATE_IP); // false

http://rogeriolino.com/2012/03/16/php-validate-filters/