Permalink
Browse files

Merge pull request #12 from k33l0r/master

Replace the email regexp in the readme with a better example
  • Loading branch information...
2 parents f5a3d13 + 05bb4bb commit db82f6b082c7127c380b49e3f6bf39f09c403844 @josevalim josevalim committed Jun 6, 2011
Showing with 4 additions and 4 deletions.
  1. +4 −4 README.rdoc
View
@@ -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 db82f6b

Please sign in to comment.