mickd wrote:is that sufficiant for checking any email format? thanks.
Nope.
It misses numerous valid combinations. Keep in mind that the email RFC is considered one of the most challenging regex combinations in the world to comply with. It was covered in 'Mastering Regular Expressions', taking several pages to solve.
I'll save you time and trouble, and post a link to the function which contains the php version of that regex:
mickd wrote: thanks for the link, damn thats some pritty complex regex there. ill test it out.
Revision: 13, Fri Aug 19 15:24:02 2005 UTC (5 weeks, 5 days ago) by Roja
nice.
Thanks.
I can't/don't take all the credit. As I mention in the file itself, its part of the project (Blacknova Traders) I contribute to, and its based off of the incredibly well done book.
But yeah, I was the one that committed it to the project.
We're redoing the whole project in SVN, which is why only a handfull of files are there at the moment. Its a pretty exciting process. Thanks for noticing the commit.
Anyways, thought to mention the book itself is available through Google Print (http://print.google.com). Just look up the title "Mastering Regular Expressions". Yep, available as in free - just keep your Google/Gmail account details handy to sign in.
There's a huge selection of O'Reilly, SAMS, and other texts available also...Some are complete, some only have sections available - but worth a look.
Most account based systems that I setup use the e-mail address as their account login as well. So allowing all RFC-compliant addressed really isn't an option. For example, allowing login names with spaces, quotes, etc. don't usually work very well (even though they would be valid e-mail addresses).
With that in mind I usually go with the following regex:
Wondeful script Roja. I'm awful at regex so I never would've figured that out. I just used a simple regex to validate before, but now my mind can rest easily knowing my e-mail validation is more complete. How complete is it really? Does it fully comply with RFC 2822 (or whatever RFC it is)? Either way, it's more complete than what I've got. Thanks a lot!
Well, it is a php version of the definitive regex for email validation from the book 'Mastering Regular Expressions'. I haven't found any errata, comments, or test-cases that show it to be inaccurate. So far, it seems to match up.
php_wiz_kid wrote:Does it fully comply with RFC 2822 (or whatever RFC it is)?
Without rehashing the whole "which rfc" argument all over again, yes, it is (to my knowledge) fully compliant with the current relevant RFC's as of today.