Here are some examples of Rails validations:
# Insure that field is nonempty.
validates :name, presence: true
# Insure that field is unique (not equal to
# an existing value) in the table.
validates :ssn, uniqueness: true
# Insure that field value is not in a given set:
validates :credit_card, exclusion: { in: %w( DinersClub
Discover MasterCard), message: "${value} not accepted." }
# Insure output is accepted by a regular expression.
validates :phone, format: { with: /\A\d{3}\/\d{3}-\d{4}\Z/,
message: " number not legal." }
# Insure that field value is in a given set:
validates :size, inclusion: { in: %w( small medium large ),
message: "#{value} should be small, medium, or large." }
# Control the size in characters of string input:
validates :bio, length: { maximum: 500 }
validates :passwd, length: { minimum: 8 }
validates :id_num, length: { in 6:12 }
validates :id_num, length: { is: 10 }
# Insures that the input is a number:
validates :gpa, numericality: true
validates :gpa, numericality: {
greater_than_or_equal_to: 0.0,
less_than_or_equal_to: 4.0 }
validates :age, numericality: {
integer_only: true }
# greater_than, less_than, equal_to,
# odd, or even are also options.