What is the best/easy way to validate an email address in Ruby?

前端 未结 10 854
刺人心
刺人心 2020-12-13 06:40

What is the best/easy way to validate an email address in ruby (on the server side)?

10条回答
  •  离开以前
    2020-12-13 06:49

    validates :email, presence: true, format: /\w+@\w+\.{1}[a-zA-Z]{2,}/
    

    checks that email field is not blank and that one or more characters are both preceding the '@' and following it

    Added specificity, any 1 or more word characters before an the @and any 1 or more word character after and in between specifically 1 . and at least 2 letters after

提交回复
热议问题