And interesting one to stumble upon – the ‘official‘ regex for validating a email address:
Edit: I’ve had to break this down into parts – for some reason WordPress throws a 403 error if I don’t. I think it sees this regex as a security risk!
Before the @ sign:
^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+
The @ sign and after:
@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)*$
Reads like it should work pretty well to me. I didn’t realise before the @ was so generous. And you could shrink it by using a case insensitive operator.
Note that as specified in the spec you link to this regex is too strict regarding the part before the @ and too loose regarding the part after.
A completely valid address like “name quot ” and at @ chars”@comp.com is going to be rejected
I actually thought this was a bit loose on the bit before the @ – I was surprised that so many characters were allowed. And on the after part, yes, I thought it was loose as well – something like @example would be valid. I thought you had to have a TLD.
Whichever, in 15 years of looking, I’ve never found a really satisfactory email address regex, so I’m almost willing to adopt a ‘standard’ one in the hope that eventually everyone complies…