0

hello I am building a rails application for the college community, the idea is that only students with a valid @college.edu email address can sign up for it.

There is a students table with college as its column

I have looked at the rails doc under validation, mostly it tells you how to validate length, presence, emptiness etc.

will this gem help me?

gem "validates_email_format_of", "~> 1.5.3"

I was reading up on email validation and it go into parsers, RFC 2822 and RFC 3696 ? is there a simpler way to go about it like regular expressions?

4

1 回答 1

1

I'm not familiar with the validates_email_format_of gem, but the following example of the use of validates is documented in http://apidock.com/rails/ActiveModel/Validations/ClassMethods/validates

validates :email, :format => { :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create }
于 2013-08-25T23:57:21.247 回答