We help IT Professionals succeed at work.

Correct syntax to find a valid yahoo email address using preg_match

evibesmusic
evibesmusic asked
on
Experts,

I am simply trying to validate the contents of a form field to ensure that a valid yahoo.com email address is used.

This is my current syntax which produces the following error:

syntax:

if(preg_match('@yahoo.com', $emailaddress)){
...
}

error:

Warning: preg_match() [function.preg-match]: No ending delimiter '@' found in C:\xampp\htdocs\oneplace\scripts\users.php on line 30

Can someone help me find what I am missing.  Looked at php.net but, wasn't able to pinpoint the error.  500 easy points up for grabs.

Cheers!
Comment
Watch Question

Web Developer, specialising in WordPress
SILVER EXPERT
Most Valuable Expert 2011
Commented:
The pattern terminators:

if(preg_match('/@yahoo.com$/i', $emailaddress)){
...
}
Terry WoodsWeb Developer, specialising in WordPress
SILVER EXPERT
Most Valuable Expert 2011
Commented:
The $ ensures the @yahoo.com is at the end of the value (so rejects "spam@yahoo.com@example.com") and the i is a pattern modifier allows the yahoo.com to be upper (or mixed) case, which is ok for a TLD.

Author

Commented:
@TerryAtOpus:

You the man.  Thanks.

Author

Commented:
Thanks!
Terry WoodsWeb Developer, specialising in WordPress
SILVER EXPERT
Most Valuable Expert 2011

Commented:
If you ever have trouble with creating a regular expression pattern for the preg_* functions, be sure to include the Regular Expressions zone in your question... thanks for the points!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.