Module: DataMapper::Validate::ValidatesFormat

Module | DataMapper::Validate::ValidatesFormat
In: | lib/dm-validations/format_validator.rb

### Methods

validates_format

### Public Instance methods

validates_format(*fields)

Validates that the attribute is in the specified format. You may use the :as (or :with, it‘s an alias) option to specify the pre-defined format that you want to validate against. You may also specify your own format via a Proc or Regexp passed to the the :as or :with options.

@option :allow_nil<Boolean> true/false (default is true) @option :as<Format, Proc, Regexp> the pre-defined format, Proc or Regexp to validate against @option :with<Format, Proc, Regexp> an alias for :as

@details [Pre-defined Formats]

      :email_address (format is specified in DataMapper::Validate::Format::Email)
      :url (format is specified in DataMapper::Validate::Format::Url)

@example [Usage]

      require 'dm-validations'

      class Page
        include DataMapper::Resource

        property :email, String
        property :zip_code, String

        validates_format :email, :as => :email_address
        validates_format :zip_code, :with => /^\d{5}$/

        # a call to valid? will return false unless:
        # email is formatted like an email address
        # and
        # zip_code is a string of 5 digits

[Validate]