diff options
-rw-r--r-- | app/models/public_body.rb | 43 | ||||
-rw-r--r-- | config/environment.rb | 3 |
2 files changed, 11 insertions, 35 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb index e7a723805..0498e3688 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -1,45 +1,20 @@ -# XXX move this to somewhere shared -def is_valid_email(addr) - # This is derived from the grammar in RFC2822. - # mailbox = local-part "@" domain - # local-part = dot-string | quoted-string - # dot-string = atom ("." atom)* - # atom = atext+ - # atext = any character other than space, specials or controls - # quoted-string = '"' (qtext|quoted-pair)* '"' - # qtext = any character other than '"', '\', or CR - # quoted-pair = "\" any character - # domain = sub-domain ("." sub-domain)* | address-literal - # sub-domain = [A-Za-z0-9][A-Za-z0-9-]* - # XXX ignore address-literal because nobody uses those... - - specials = '()<>@,;:\\\\".\\[\\]' - controls = '\\000-\\037\\177' - highbit = '\\200-\\377' - atext = "[^#{specials} #{controls}#{highbit}]" - atom = "#{atext}+" - dot_string = "#{atom}(\\s*\\.\\s*#{atom})*" - qtext = "[^\"\\\\\\r\\n#{highbit}]" - quoted_pair = '\\.' - quoted_string = "\"(#{qtext}|#{quoted_pair})*\"" - local_part = "(#{dot_string}|#{quoted_string})" - sub_domain = '[A-Za-z0-9][A-Za-z0-9-]*' - domain = "#{sub_domain}(\\s*\\.\\s*#{sub_domain})*" - - is_valid_address_re = Regexp.new("^#{local_part}\\s*@\\s*#{domain}\$") - - return addr =~ is_valid_address_re -end +# models/info_request.rb: +# A public body, from which information can be requested. +# +# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. +# Email: francis@mysociety.org; WWW: http://www.mysociety.org/ +# +# $Id: public_body.rb,v 1.4 2007-08-31 17:56:01 francis Exp $ class PublicBody < ActiveRecord::Base validates_presence_of :request_email def validate - unless is_valid_email(request_email) + unless MySociety::Validate.is_valid_email(request_email) errors.add(:request_email, "doesn't look like a valid email address") end if complaint_email != "" - unless is_valid_email(complaint_email) + unless MySociety::Validate.is_valid_email(complaint_email) errors.add(:complaint_email, "doesn't look like a valid email address") end end diff --git a/config/environment.rb b/config/environment.rb index 462eb4dc0..ade28bba0 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -61,6 +61,7 @@ end ActiveRecord::Errors.default_error_messages[:blank] = "must be filled in" # Include your application configuration below - +$:.push("../rblib") +load "validate.rb" |