Luigi
Luigi

Reputation: 5603

rails 4 validate presence of specific domain in email

I need to validate that my :email attribute includes a specific attribute - @kodak.com.

How can I do that? I am using Rails 4.

Something like:

validates_inclusion_of :email, '@kodak.com'

Upvotes: 2

Views: 2089

Answers (1)

Agis
Agis

Reputation: 33626

You can do this:

validates :email, format: { with: /\b[A-Z0-9._%a-z\-]+@kodak\.com\z/,
                  message: "must be a kodak.com account" }

Upvotes: 10

Related Questions