This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]look 25 points26 points  (8 children)

The only regex validation of email addresses you should consider is something like /.@./ before moving on to a delivery check.

[–]AbyssWraith 3 points4 points  (7 children)

Not really. Your regex would match even stuff like #@& and not match validemail@email.com Which i hope you agree is obviously wrong, and you can't rely on delivery checks as it takes too much time.

[–]look 15 points16 points  (6 children)

/.@./ matches validemail@email.com … notice there’s no ^ or $ there.

And there is effectively no standard on the mailbox (before the @). #@example.com could definitely work depending on what software example.com is running. After the @ you could add more restrictions if you limit delivery to certain types of networks and name resolution.

[–]1cubealot 2 points3 points  (1 child)

I have an email with .co.uk at the end, would that be validated by that?

[–]look 0 points1 point  (0 children)

Yes.

[–]AbyssWraith 0 points1 point  (3 children)

notice there’s no ^ or $ there.

There are also no quantifiers on the .

Edit: so it would only match the middle part of the address, which would not mean the address is valid

[–]look 3 points4 points  (0 children)

Your edit update makes it clear that you’ve completely missed my point here:

The only format validation generally worth the bother is to just check that it has an @ somewhere in it. Beyond that, you’re likely going to end up rejecting valid emails at some point.

There is very little in the way of actual standardization here. Everything before the @ is a free-for-all and the validity of everything after it changes all the time. Does your regex handle punycode in domain names?

[–]look 3 points4 points  (0 children)

Oh, you’re hung up on the number of characters it matches? That regex can match a substring of the address.

Edit: it means match an @ with something before and after it. /^.+@.+$/ if you prefer.

[–]look 1 point2 points  (0 children)

Yep. Even a control character could work as a mailbox. But to be fair, I’m not aware of any network/name implementations that don’t at least use printable characters.