Basic ident and phone validations

This commit is contained in:
Andres Keskküla 2014-07-25 14:19:21 +03:00
parent 256f564327
commit 1645b3e96f
6 changed files with 45 additions and 3 deletions

View file

@ -1,7 +1,16 @@
class Contact < ActiveRecord::Base
#TODO Estonian id validation
#TODO Foreign contact will get email with activation link/username/temp password
#TODO Phone number validation, in first phase very minimam in order to support current registries
has_many :addresses
validate :ident_must_be_valid
validates :phone, format: { with: /\+\d{3}\.\d+/, message: "bad format" }
def ident_must_be_valid
#TODO Ident can also be passport number or company registry code.
#so have to make changes to validations (and doc/schema) accordingly
return true unless ident.present?
code = Isikukood.new(ident)
errors.add(:ident, 'bad format') unless code.valid?
end
end