In an ActiveRecord
model, are there any static/canned formats I can use? For instance, when validating the format of an email address I can either make a static regex to reuse on other models or perhaps use some static that already exists in the framework.
class Contact < ActiveRecord::Base
EMAIL_FORMAT = /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
attr_accessible :first_name, :last_name, ..., :email
validates :email, :format => EMAIL_FORMAT
end
I figured I'd be able to simply do:
validates :email, :format => ActiveRecord::SOME_STATIC_EMAIL_FORMAT
or:
validates :email, :format => :email