A Few Handy PHP Regular Expressions (RegEx)
Email Address:
'/^[^/W][a-zA-Z0-9_-]+(/.[a-zA-Z0-9_-]+)*/@[a-zA-Z0-9-]+(/.[a-zA-Z0-9-]+)*/.[a-zA-Z]{2,6}$/'
Matches: john.doe@domain.edu This e-mail address is being protected from spam bots, you need JavaScript enabled to view it , john_doe@do.main.edu This e-mail address is being protected from spam bots, you need JavaScript enabled to view it , john-doe@do-main.edu This e-mail address is being protected from spam bots, you need JavaScript enabled to view it , john@doe.gov.us This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
Domain Name 1: This only matched simple domain names
'/^([a-zA-Z0-9-]+)/.[a-zA-Z]{2,6}$/'
Matches: domain.com, domain.net
Non-matches: sub.domain.com, domain.uni.cc, domain.ne.jp
Domain Name 2: This only matches complex domain names
'/^([a-zA-Z0-9-]+)/.[a-zA-Z]{2,3}/.[a-zA-Z]{2}$/'
Matches: domain.uni.cc, domain.ne.jp
Non-matches: sub.domain.com, domain.com
Sub Domain: This will only match for a sub domain of the specified domain
'/^[a-zA-Z0-9-]+/.realdomainname/.com$/ '
Matches: help.realdomainname.com, subdomain.realdomainname.com
Non-matches: sub.domain.com, help.realdomainname.net
Sub Domain: This will only match for a sub domain of the specified domain
'/^[a-zA-Z0-9-]+/.realdomainname/.com$/ '
Matches: help.realdomainname.com, subdomain.realdomainname.com
Non-matches: sub.domain.com, help.realdomainname.net