Module: DataMapper::Validations::ValidatesFormat

### Home Classes Methods

### In Files

- lib/dm-validations/validators/format_validator.rb

### Methods

- #validates_format_of

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- DataMapper
- DataMapper::InvalidContextError
- DataMapper::Validate
- DataMapper::ValidationError
- DataMapper::Validations
- DataMapper::Validations::AbsenceValidator
- DataMapper::Validations::AcceptanceValidator
- DataMapper::Validations::AutoValidations
- DataMapper::Validations::AutoValidations::ModelExtension
- DataMapper::Validations::ClassMethods
- DataMapper::Validations::ConfirmationValidator
- DataMapper::Validations::Context
- DataMapper::Validations::ContextualValidators
- DataMapper::Validations::Format
- DataMapper::Validations::Format::Email
- DataMapper::Validations::Format::Url
- DataMapper::Validations::FormatValidator
- DataMapper::Validations::GenericValidator
- DataMapper::Validations::LengthValidator
- DataMapper::Validations::MethodValidator
- DataMapper::Validations::NumericalityValidator
- DataMapper::Validations::OrderedHash
- DataMapper::Validations::PresenceValidator
- DataMapper::Validations::PrimitiveTypeValidator
- DataMapper::Validations::UniquenessValidator
- DataMapper::Validations::UnknownValidationFormat
- DataMapper::Validations::ValidatesAbsence
- DataMapper::Validations::ValidatesAcceptance
- DataMapper::Validations::ValidatesConfirmation
- DataMapper::Validations::ValidatesFormat
- DataMapper::Validations::ValidatesLength
- DataMapper::Validations::ValidatesNumericality
- DataMapper::Validations::ValidatesPresence
- DataMapper::Validations::ValidatesPrimitiveType
- DataMapper::Validations::ValidatesUniqueness
- DataMapper::Validations::ValidatesWithBlock
- DataMapper::Validations::ValidatesWithMethod
- DataMapper::Validations::ValidatesWithin
- DataMapper::Validations::ValidationErrors
- DataMapper::Validations::WithinValidator
- Object

No matching classes.

# DataMapper::Validations::ValidatesFormat

### Public Instance Methods

validates_format_of(*fields) click to toggle source

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 [Boolean] :allow_nil (true)

    true or false.

@option [Boolean] :allow_blank (true)

    true or false.

@option [Format, Proc, Regexp] :as

    The pre-defined format, Proc or Regexp to validate against.

@option [Format, Proc, Regexp] :with

    An alias for :as.

    :email_address (format is specified in DataMapper::Validations::Format::Email - note that unicode emails will *not* be matched under MRI1.8.7)
    :url (format is specified in DataMapper::Validations::Format::Url)

@example Usage

    require 'dm-validations'

    class Page
      include DataMapper::Resource

      property :email, String
      property :zip_code, String

      validates_format_of :email, :as => :email_address
      validates_format_of :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

    # File lib/dm-validations/validators/format_validator.rb, line 117
    def validates_format_of(*fields)
      validators.add(FormatValidator, *fields)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.