ericp Posted December 12, 2013 Share Posted December 12, 2013 Hi Larry, Your pattern ^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$ provides for reasonably good email validation. However, your tip #2 warns that it will allow some invalid addresses to pass through (like ones starting with a period or containing multiple periods together). So, can I eliminate this by going with the word boundaries like this: \b[\w.-]+@[\w.-]+.[A-Za-z]{2,6}\b If you, and other forum participants, also find it 'not good at all' or 'worse than the original one', please share your ideas and reasons as I really want to strive for the better one for it. Thanks in advance. Eric Link to comment Share on other sites More sharing options...
HartleySan Posted December 12, 2013 Share Posted December 12, 2013 Here's a good start to the discussion on handling email addresses with a regex: http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address Link to comment Share on other sites More sharing options...
Larry Posted December 12, 2013 Share Posted December 12, 2013 Thanks, Eric. To be frank, when I need to validate email addresses, I use the Filter extension. I use an email address as an example in the book, as it's a good teaching example. So if you want to try to make a better email pattern, that's all good and fine, but if your goal is to do a better job validating email addresses, then you using use Filter. Link to comment Share on other sites More sharing options...
HartleySan Posted December 12, 2013 Share Posted December 12, 2013 Yes, I agree with Larry. Using the filter_var function is the way to go in PHP. Link to comment Share on other sites More sharing options...
ericp Posted December 12, 2013 Author Share Posted December 12, 2013 To discuss further away from the topic and the book's content, but in the same area, I happened to see this website: http://tools.email-checker.com/ Do you think that PHP can perform the same tasks as that website does? If yes, do you have any book about this, Larry? or do you know any online resources to point to so that I can learn more and share more about it? Eric Link to comment Share on other sites More sharing options...
Larry Posted December 13, 2013 Share Posted December 13, 2013 You could write that in PHP, although I've never done that nor explained it. But, really, if you're looking to validate that an email address is an actual, live, email address that the user has access to, there's only one best way to do that: send them an email that contains a link back to your site that they have to click. Even that site/approach only verifies that the email address exists. It doesn't confirm that it's the user's email address (e.g., I could provide your email address, not mine, to that site, and get a positive result) or that it's an email address the user regularly accesses. Link to comment Share on other sites More sharing options...
Recommended Posts