Class: IsCuracaoPhoneValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/app/validators/is_curacao_phone_validator.rb

Overview

usage:

in your model, add:

validates :email, :presence => true, :is_email_address => true;

taken from lindsaar.net/2010/1/31/validates_rails_3_awesome_is_true (It’s probably a fake regex but hey, it looks legit.)

Instance Method Summary collapse

Instance Method Details

#error_messageObject



8
9
10
# File 'lib/app/validators/is_curacao_phone_validator.rb', line 8

def error_message
  "is geen geldig Curaçao telefoon nummer."
end

#help_messageObject



12
13
14
# File 'lib/app/validators/is_curacao_phone_validator.rb', line 12

def help_message
  "Telefoonnummer moet 7 cijfers zijn, bijvoorbeeld 6781256."
end

#validate_each(record, attribute, value) ⇒ Object



16
17
18
19
20
# File 'lib/app/validators/is_curacao_phone_validator.rb', line 16

def validate_each(record, attribute, value)
  unless value =~ /[4-8][0-9]{6}/
    record.errors[attribute] << (options[:message] || error_message )
  end
end