I have the following in my user.rb model:

```
INVALID_EMAILS = %w(gmail.com hotmail.com)
validates_format_of :email, :without => /#{INVALID_EMAILS.map{|a| Regexp.quote(a)}.join('|')}/, :message => "That email domain won't do.", :on => :create

```

For various reasons, I want to be able to use this logic in my controller to check an email's input before it is user.created, which is when the above normall runs.

How can I turn the above into a method that I can call in controllers other than user? Possible?

And if is called and returned false I then want to do errors.add so I can let the user know why?

Thanks

**Trying:**

```
  def validate_email_domain(emailAddy)
    INVALID_EMAILS = %w(gmail.com googlemail.com yahoo.com ymail.com rocketmail.com hotmail.com facebook.com)
    reg = Regexp.new '/#{INVALID_EMAILS.map{|a| Regexp.quote(a)}.join('|')}/'
    self.errors.add('rox', 'Hey, Ruby rox. You have to say it !') unless reg.match attribute
  end

```

**Update:**

```
..
  Rails.logger.info validate_email_domain(email)
...

  def valid_email_domain(emailAddy)
    reg = Regexp.new '/#{User::INVALID_EMAILS.map{|a| Regexp.quote(a)}.join("|")}/'
    return true if emailAddy.scan(reg).size == 0
  end

```