Q:

Rails validation confirm true is not case sensitive?

In my user.rb model, I have a email_confirm field, so that users insert twice and validate the emails without typos 
attr_accessor :email_confirmation
validates :email, confirmation: true, on: :create
validates :email_confirmation, presence: true, allow_nil: true

But what happens is, if I insert an email with a capital letter, I get an validation error "don't match". How do I confirm emails without case sensitive? 
I'm using devise

A:

For email validation, use a regex matcher:
validates_format_of :email, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i

The i flag at the end of the regex sets case insensitivity. This validation also handles presence, since nil or a blank string would fail the above validation.
I recommend using Rubular for testing regexes: http://rubular.com/
EDIT
You can preprocess the attribute in a before_validation block:
before_validation :downcase_email

def downcase_email
  email_confirmation.try(:downcase!)
  email.try(:downcase!)
end

try is to prevent calling downcase! if email is nil.

