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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.