Sha256: 817b817500b91f0a53ef6baea8a49767c7f570c66bcb182e9802fa8e8cc083f9

Contents?: true

Size: 397 Bytes

Versions: 5

Compression:

Stored size: 397 Bytes

Contents

require 'active_model'

class BicValidator < ActiveModel::EachValidator

  def validate_each(record, attribute, value)
    record_error(record, attribute, value) unless value =~ BicValidator.regexp
  end
  
  private
  
  def record_error(record, attribute, value)
    record.errors.add(attribute, (options[:message] || :invalid_bic))
  end

  def self.regexp
    /[A-Z]{6}[A-Z0-9]{2,}/
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bank-validator-0.2.8 lib/active_model/bic_validator.rb
bank-validator-0.2.7 lib/active_model/bic_validator.rb
bank-validator-0.2.6 lib/active_model/bic_validator.rb
bank-validator-0.2.5 lib/active_model/bic_validator.rb
bank-validator-0.2.4 lib/active_model/bic_validator.rb