How do I specify the regular expression to disable the use of underscores after the '@' sign in php for email validation?
Posted
by
Qlidnaque
on Stack Overflow
See other posts from Stack Overflow
or by Qlidnaque
Published on 2011-01-11T11:45:52Z
Indexed on
2011/01/11
11:53 UTC
Read the original article
Hit count: 170
Currently the following email in the script validates even though there are no underscores indicated in the second part of the regular expression validation after the '@' sign. How do I make underscores invalid in the second part of the email?
<?php
$email = 'firstname.lastname@a_aa.bbb.co_m';
$regexp = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9]+([.][A-z0-9]+)*[.][A-z]{2,4}$/";
if (preg_match($regexp, $email)) {
echo "Email address is valid.";
} else {
echo "Email address is <u>not</u> valid.";
}
?>
© Stack Overflow or respective owner