IwnfuM Posted August 23, 2010 Share Posted August 23, 2010 this syntax is good to check email like this email ? ([a-zA-Z0-9]+)@([a-zA-Z0-9]+)[.]([a-zA-Z0-9]+) . and a questions. how does i tell the syntax to notice if there is a dot. what is the meaning of ( this / thing ) . and what the meaning of () . thanks , Mor. Quote Link to comment Share on other sites More sharing options...
ZachMEdwards Posted August 23, 2010 Share Posted August 23, 2010 Well to match an email address according to RFC 2822 standard, you have to use this pattern: '/(?:[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(??:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(??:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/i' Which is suggested not to use. Here's a simplified version, and probably the best to use: '/[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i' To answer your questions: To show a dot, use \. It will escape the . (dot) character, so it matches "." The forward slash "/" is used to show the start or end of the regular expression. The parentheses are used as capturing groups. They capture what's inside them, for example: $str = "My name is Susan. My name is Robert."; preg_match_all('/My name is ([^.]+)\./', $str, $matches); print_r($matches); Run that script! Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted August 24, 2010 Share Posted August 24, 2010 You can validate emails with filter_var if it's available to you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.