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

前端 未结 10 923
刺人心
刺人心 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:56

    If you are using Rails/Devise - addition to @apneadiving`s answer -

    validates_format_of :email,:with => Devise::email_regexp
    

    Devise::email_regexp is taken from config/initializers/devise.rb

    config.email_regexp = /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/
    

提交回复
热议问题