Welcome Guest, Not a member yet? Register   Sign In
Allowing apostrophes in a valid email address
#1

[eluser]Unknown[/eluser]
Hi,

I have recently tried importing an xml document of users using CI and have found that using the valid email helper it failed quite a few addresses that had apostrophe in their name such as Chris.D'[email protected]

The RFC 2822 Specification actually allows all kinds of strange ASCII characters in the local-part, and whilst most of these are not allowed in most systems, and shouldn't be, I really think the apostrophe should be included in the regex along with the +_ in the valid email check.

At the moment I just extend the email helper with my own version below

Code:
function valid_email($address)
{
   return ( ! preg_match("/^([a-z0-9\+_\-']+)(\.[a-z0-9\+_\-']+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $address)) ? FALSE : TRUE;
}

Its really minor, but has anyone else the same problem with apostrophes in email addresses and think that it should be submitted as as bug?
#2

[eluser]Derek Allard[/eluser]
We've been down this road with EE. I think the nutshell version is that it caused far more grief to allow apostrophe's then to block them. Your solution (extending the helper) would be my recommendation at this time.

Hey Phil, welcome to CI!
#3

[eluser]kevinprince[/eluser]
Going to bump this rather than start a new thread.

I am getting invalid email responses on email addresses which to me look valid eg: [email protected]

I have not modified the helper so any help appreciated
#4

[eluser]Derek Allard[/eluser]
I think you may want to start a new thread. This one is about apostrophes in email, so email error responses are probably best dealt with separately. Plus, it'll get your issue more visibility.
#5

[eluser]drewbee[/eluser]
Hmm. Shouldn't the validation routine come pre-packed with what is detailed in the RFC?

Derek,

Can you provide the link (if there is one) to the dicussion regarding EE and this issues that were discussed? I would like to read over that.
#6

[eluser]Derek Allard[/eluser]
Hey Drewbee, sure, if you hit the EE forums and search you will find lots of discussion. The crux is that despite the apostrophe being technically legal, in practical terms many systems forbid it, and for playing it safe, we have also.

A similar issue, (following the technical standards vs doing what works in the real world), comes up every time you validate your xhtml. The validator suggests you send the mime-type "application/xhtml+xml". The problem though is that some browsers (cough, cough, I'm looking at you IE) don't handle this properly. So you end up needing to choose between supporting a browser used by 70-75% of the planet, or following the standards. In CI, (and EE), we've opted for the former.

I hope that helps understand why we made the choice. That said, extending the helper is an easy, portable, future proof solution.
#7

[eluser]drewbee[/eluser]
Thanks for the insight. Horray for another 'ie did not follow the standards, but chose to do there own thing' to the ever growing list lol.
#8

[eluser]Gnative[/eluser]
Incase someone else comes to this post.. this ha sheen resolved in the developer version of codeigniter.

https://github.com/EllisLab/CodeIgniter/issues/3116

Be sure to also update the Form_validation class as the email validation function there is different from the email_helper functions.




Theme © iAndrew 2016 - Forum software by © MyBB