Sha256: c41c5607749488a8566ebc92605d81ea357e9deeea2dcdf03a0794371bd9c908

Contents?: true

Size: 782 Bytes

Versions: 16

Compression:

Stored size: 782 Bytes

Contents

# encoding: utf-8
module SexyValidations
  module Validators
    class Password
      def self.validate(record, attribute, value, options)
        return unless value

        unless options.is_a?(Hash)
          options = {}
        end

        options[:length] ||= 6..20
        options[:format] ||= /^[\x20-\x7e]+$/i

        min = options[:length].min
        if value.length < min
          record.errors.add(attribute, "zu kurz (mindestes #{min} Zeichen)")
        end

        max = options[:length].max
        if value.length > max
          record.errors.add(attribute, "zu lang (maximal #{max} Zeichen)")
        end

        unless value =~ options[:format]
          record.errors.add(attribute, "enthält ungültige Zeichen")
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
sexy_validations-0.5.4 lib/sexy_validations/validators/password.rb
sexy_validations-0.5.3 lib/sexy_validations/validators/password.rb
sexy_validations-0.5.2 lib/sexy_validations/validators/password.rb
sexy_validations-0.5.1 lib/sexy_validations/validators/password.rb
sexy_validations-0.5.0 lib/sexy_validations/validators/password.rb
sexy_validations-0.4.3 lib/sexy_validations/validators/password.rb
sexy_validations-0.4.2 lib/sexy_validations/validators/password.rb
sexy_validations-0.4.1 lib/sexy_validations/validators/password.rb
sexy_validations-0.4.0 lib/sexy_validations/validators/password.rb
sexy_validations-0.3.1 lib/sexy_validations/validators/password.rb
sexy_validations-0.3.0 lib/sexy_validations/validators/password.rb
sexy_validations-0.2.2 lib/sexy_validations/validators/password.rb
sexy_validations-0.2.1 lib/sexy_validations/validators/password.rb
sexy_validations-0.2.0 lib/sexy_validations/validators/password.rb
sexy_validations-0.1.0 lib/sexy_validations/validators/password.rb
sexy_validations-0.0.1 lib/sexy_validations/validators/password.rb