Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Simple Email Address Syntax Validation

// Basic email address syntax validation
// If the address is not formatted properly this will throw an error.

   System.Net.Mail.MailAddress temp = new System.Net.Mail.MailAddress(emailAddress);

sample of dutch validation error messages

//Dutch validation error messages
//Put this at the end of environment.rb

module ActiveRecord
  class Errors
    begin
      @@default_error_messages = {
        :empty => "dient verplicht ingevuld te worden",
        :blank => "dient verplicht ingevuld te worden",
      }
    end
  end
end

Custom Validation in ActiveRecord

// allows adding errors in methods other than validate

  def other_errors=(err)
    write_attribute(:other_errors,Array.new) if !self.other_errors
    self.other_errors[self.other_errors.length] = err
  end
	
  def other_errors
    read_attribute(:other_errors)
  end

  def validate
    if self.other_errors
      self.other_errors.each {|x| errors.add_to_base(x)}
      return
    end
    return if !errors.empty?
  end