Ruby Email validation with regex

前端 未结 9 910
有刺的猬
有刺的猬 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:48

    I guess the example from the book can be improved to match emails with - in subdomain.

    VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
    

    For example:

    > 'some@email.with-subdomain.com' =~ VALID_EMAIL_REGEX
    => 0
    

提交回复
热议问题