Sha256: 5700e56efbd96821bd31e07b10e1153a43d82d73f57ec5867ef764dde3b9d4ba

Contents?: true

Size: 745 Bytes

Versions: 36

Compression:

Stored size: 745 Bytes

Contents

# -*- encoding : utf-8 -*-
# == usage:
# in your model, add:
#  validates :id_number, must_be_present => true, is_a_curacao_id_number => true;
class IsACuracaoIdNumberValidator < ActiveModel::EachValidator

  def validate_each(record, attribute, value)
    if value =~ /^[0-9]{10}$/
      year  = value[0..3].to_i
      month = value[4..5].to_i
      day   = value[6..7].to_i
      number= value[8..9].to_i
      begin
        DateTime.civil(year, month, day)
      rescue ArgumentError
        record.errors.add(attribute.to_sym, options[:message] || "too_short" )
      end
    else
      record.errors.add(attribute.to_sym, options[:message] || "not_a_number" )
    end
  end

end

#"moet bestaan uit tien cijfers (bijvoorbeeld 1983040812)."

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
inline_forms-1.3.49 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.48 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.47 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.45 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.44 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.43 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.42 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.41 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.40 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.39 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.38 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.37 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.36 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.35 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.34 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.33 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.32 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.31 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.30 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.29 lib/app/validators/is_a_curacao_id_number_validator.rb