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

后端 未结 12 1307
感情败类
感情败类 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:53

    Using regular expressions for this is not a good idea, as has been demonstrated at length in those other posts.

    I suppose people keep doing it because they don't know any better or don't care.

    Will a parser be any better? Maybe, maybe not.

    I maintain that sending a verification e-mail is the best way to validate it. If you want to check anything from JavaScript, then check that it has an '@' sign in there and something before and after it. If you go any stricter than that, you risc running up against some syntax you didn't know about and your validator will become overly restrictive.

    Also, be careful with that TLD validation scheme of yours, you might find that you are assuming too much about what is allowed in a TLD.

提交回复
热议问题