View Full Version : pattern matching
Rain Designs
06-21-2003, 11:08 AM
I know this is a pretty basic question, but I couldn't find any good documentation online, nor in this forum. So heres my question: How would I check to make sure the user input an email address. I'm guessing something like this:
if ($_POST["email"] == '/\\s*@\\s*.\\s*')
???? thats gotta be wrong, I'm trying to remember perl expressions from way back when :D
Thanks for the help,
Alex
darksidepuffin
06-21-2003, 11:43 AM
seek and ye shall find:
http://www.sitepoint.com/article/974
[edit: wrong url :P fixed]
tonto
06-21-2003, 11:51 AM
if (!eregi ("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}$", $email) {
echo "Not a valid email" ;
}
else {
echo "Valid email" ;
}
Rain Designs
06-21-2003, 12:00 PM
sweet, thanks for the help!
Alex
scoutt
06-21-2003, 12:28 PM
many ways to do it.
if (!preg_match('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+@([-0-9A-Z]+\.)+([0-9A-Z]){2,4}$/i', $email)) {
$errmsg = "Sorry your email is invalid, please try again";
}
tonto: using the php code tags strips most of that reg exp out.
Gregory
06-21-2003, 01:01 PM
now theres some complex looking code if i ever saw some!
Rain Designs
06-21-2003, 05:49 PM
I was thinking the same :D
Thanks again for the help
Alex
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.