How to change PHP's eregi to preg_match
Posted
by
jasondavis
on Stack Overflow
See other posts from Stack Overflow
or by jasondavis
Published on 2009-09-03T17:42:03Z
Indexed on
2011/01/08
13:54 UTC
Read the original article
Hit count: 202
I need help, below is a small VERY basic regex to somewhat validate an email, I do realize it does not work the greatest but for my needs it is ok for now.
It currently uses PHP's eregi function which php.net says is now a depreciated function and I should use preg_match instead, simply replacing erei with preg_match does not work, can someone show me how to make it work?
function validate_email($email) {
if (!eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", $email)) {
echo 'bad email';
} else {
echo 'good email';
}
}
function validate_email($email) {
if (!preg_match("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", $email)) {
echo 'bad email';
} else {
echo 'good email';
}
}
© Stack Overflow or respective owner