What's wrong with this RegEx for validating emails?

后端 未结 5 1643
轻奢々
轻奢々 2020-12-11 04:40

Here\'s a regex for validating emails - \\S+@\\S+\\.\\S+, I didn\'t write it. I\'m new to Regular Expressions and do not understand them all that well.

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-11 04:41

    What's wrong with the above RegEx?
    The RFC822 standard for email addresses is very loose, so it is hard to find a terse regular expression that captures all possible valid emails. The matter is complicated by the fact that not every mail server/client enforces this standard, so the actual data might be

    While you can certainly guess, or enforce a particular format, writing an ad-hoc expression is pretty much a guarantee that you will have either lots of junk email addresses or deny valid ones.

    What's a good RegEx for validating emails?
    This is the reference regex for validating against the RFC, its implemented as a perl module here, but is also the final listing in O'Reillys "Mastering Regular Expressions"

    Mail::RFC822::Address

提交回复
热议问题