Email extension check

Great if you want to make sure an email ends in a certain extension.

<?php
# @param $email   string   the email to validate   
# @param $ext     string   the extension the email should have
#
# @return bool
function check_ext($email, $ext = '.edu')
{
    return (substr($email, -(strlen($ext))) === $ext); 
}
?>

Usage

var_dump(check_ext('student@school.edu', '.edu')); // bool(true) var_dump(check_ext('hobo@bums.com', '.edu')); // bool(false)


Comments

guest
Posted on 02.09.2010 09:19

Test

Add your comment