Validation specific email specific domain devise 3 ruby on rails 4

后端 未结 1 1762
青春惊慌失措
青春惊慌失措 2021-01-24 21:15

I previously posted a question about how to use validations to only allow visitor using an email address ending with @grenoble-em.com to be able to register on my website. I am

相关标签:
1条回答
  • 2021-01-24 22:04

    If you simply want to validate that the email contains that domain, and not much else, you can add this validator:

    class User < ActiveRecord::Base
      validates_format_of :email, with: /\@grenoble-em\.com/, message: 'You should have an email from grenoble-em.com'
    end
    

    You can read more about all the validators here: http://api.rubyonrails.org/classes/ActiveModel/Validations/HelperMethods.html

    0 讨论(0)
提交回复
热议问题