81

Don't mind me, just writing maintainable, legible, commented and documented code. What's that, an email validation? Let me just
/^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i

Comments
  • 30
    RFC 5322 standard (yes that's an actual thing) is

    (?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])
  • 8
    Your keyboard just puked
  • 7
    @Verstrahlter why don't you allow subdomains? i@send.nud.es wouldn't be possible with yours if im correct
  • 6
    @gitreflog wait you mean that block of text means something? /s
  • 5
    @DeveloperACE come on. Thats one of the most readable regexes i ever saw?
  • 2
    @gitreflog Oh wow, actually after trying just a little bit, it is not hard to read at all! I just saw so many symbols, I gave up without trying... Anyway, wouldn't it be easier to specify the allowed chars, instead of the opposite? (I guess it would make it more clear)
  • 4
    Email validation should be far simpler. If the email has an @ and at least one . in it, let it be.
  • 2
    @monr0e Does not even have to have a dot technically

    Great Talk on the matter of validating E-Mail-Addresses:

    https://youtu.be/xxX81WmXjPg
  • 1
    Or just set the input type to email and set it as required, and let HTML5 do the work.
  • 4
    Email validation is best done by sending an actual email.
  • 0
    Email addresses are not parsable by regular expressions. Please never even try, it has long been proven to be impossible.
Add Comment