Ruby Email validation with regex

前端 未结 9 899
有刺的猬
有刺的猬 2020-12-03 00:21

I have a large list of emails I am running through. A lot of the emails have typos. I am trying to build a string that will check valid emails.

this is what I have

9条回答
  •  情深已故
    2020-12-03 00:59

    Here's a great article by David Celis explaining why every single regular expression you can find for validating email addresses is wrong, including the ones above posted by Mike.

    From the article:

    The local string (the part of the email address that comes before the @) can contain the following characters:

        `! $ & * - = ` ^ | ~ # % ' + / ? _ { }` 
    

    But guess what? You can use pretty much any character you want if you escape it by surrounding it in quotes. For example, "Look at all these spaces!"@example.com is a valid email address. Nice.

    If you need to do a basic check, the best regular expression is simply /@/.

提交回复
热议问题