Jump to content

preg_match for email address


HDFilmMaker2112

Recommended Posts

Could somebody break down for me what the below actually does? I found the snippet on php.net. I've read up a little bit on reg expressions but it's still a little unclear to me. 

 

I get the [] means don't include that character. But then how does the [a-zA-Z0-9._-] work?

 

preg_match('/^[^@]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$/', $email)

Link to comment
https://forums.phpfreaks.com/topic/240077-preg_match-for-email-address/
Share on other sites

Plus sign means 1 or more occurances of [a-zA-Z0-9._-] pattern, then theres \. which means dot before the email ending or extension (.com/org etc), then [a-zA-Z]+$ means alphabets 1 or more at the. [^@] at the start means the email cannot start with @-sign, ^-sign inside pattern is a negation. That is if I remember it correctly. Theres a great regexp tutorial here: http://www.regular-expressions.info/ . It would be much more beneficial for you to understand how they work instead of everytime you face a regular expression you ask people to explain it bit by bit.

 

Don't think thats even a correct regexp for email(?) I might be mistaken also though.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.