Why are people using regexp for email and other complex validation?

后端 未结 12 1349
感情败类
感情败类 2020-12-16 16:01

There are a number of email regexp questions popping up here, and I\'m honestly baffled why people are using these insanely obtuse matching expressions rather than a very si

12条回答
  •  臣服心动
    2020-12-16 16:45

    I don't believe correct email validation can be done with a single regular expression (now there's a challenge!). One of the issues is that comments can be nested to an arbitrary depth in both the local part and the domain.

    If you want to validate an address against RFCs 5322 and 5321 (the current standards) then you'll need a procedural function to do so.

    Fortunately, this is a commodity problem. Everybody wants the same result: RFC compliance. There's no need for anybody to write this code ever again once it's been solved by an open source function.

    Check out some of the alternatives here: http://www.dominicsayers.com/isemail/

    If you know of another function that I can add to the head-to-head, let me know.

提交回复
热议问题