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.28 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.27 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.26 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.25 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.24 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.23 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.22 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.21 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.20 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.19 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.18 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.17 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.16 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.15 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.14 lib/app/validators/is_a_curacao_id_number_validator.rb
inline_forms-1.3.13 lib/app/validators/is_a_curacao_id_number_validator.rb