Browse files

Replaces the example email regexp with a better example.

  • Loading branch information...
1 parent f5a3d13 commit 05bb4bb8cf38f74ec32511a023f838ce64ca2b10 @matiaskorhonen matiaskorhonen committed Jun 6, 2011
Showing with 4 additions and 4 deletions.
  1. +4 −4 README.rdoc
@@ -17,7 +17,7 @@ if you want to make a contact form just the following lines are needed (includin
class ContactForm < MailForm::Base
attribute :name, :validate => true
- attribute :email, :validate => /[^@]+@[^\.]+\.[\w\.\-]+/
+ attribute :email, :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
attribute :file, :attachment => true
attribute :message
@@ -50,12 +50,12 @@ as ActiveModel::Validation, ActiveModel::Translation and ActiveModel::Naming.
This bring I18n, error messages, validations and attributes handling like in
ActiveRecord to MailForm, so MailForm can be used in your controllers and form builders without extra tweaks. This also means that instead of the following:
- attribute :email, :validate => /[^@]+@[^\.]+\.[\w\.\-]+/
+ attribute :email, :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
You could actually do this:
attribute :email
- validates_format_of :email, :with => /[^@]+@[^\.]+\.[\w\.\-]+/
+ validates_format_of :email, :with => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
Choose the one which pleases you the most. For more information on the API, please
continue reading below.
@@ -120,7 +120,7 @@ Examples:
class ContactForm < MailForm::Base
attributes :name, :validate => true
- attributes :email, :validate => /[^@]+@[^\.]+\.[\w\.\-]+/
+ attributes :email, :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
attributes :type, :validate => ["General", "Interface bug"]
attributes :message
attributes :screenshot, :attachment => true, :validate => :interface_bug?

0 comments on commit 05bb4bb

Please sign in to comment.