mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
parent
9e8f806a43
commit
71b92afba3
2 changed files with 6 additions and 6 deletions
|
@ -19,10 +19,10 @@ class Contact < ActiveRecord::Base
|
|||
|
||||
accepts_nested_attributes_for :legal_documents
|
||||
|
||||
validates :name, :phone, :email, :ident, :ident_type, presence: true
|
||||
validates :name, :email, :ident, :ident_type, presence: true
|
||||
validates :street, :city, :zip, :country_code, presence: true, if: 'self.class.address_processing?'
|
||||
|
||||
validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/, phone: true
|
||||
validates :phone, presence: true, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/, phone: true
|
||||
|
||||
validates :email, format: /@/
|
||||
validates :email, email_format: { message: :invalid }, if: proc { |c| c.email_changed? }
|
||||
|
|
|
@ -2,11 +2,11 @@ class PhoneValidator < ActiveModel::EachValidator
|
|||
def validate_each(record, attribute, value)
|
||||
return if record.errors[:phone].any?
|
||||
|
||||
splitted_phone = value.split('.')
|
||||
country_code = splitted_phone.first
|
||||
phone_number = splitted_phone.second
|
||||
phone_parts = value.split('.')
|
||||
country_code = phone_parts.first
|
||||
subscriber_no = phone_parts.second
|
||||
|
||||
if zeros_only?(country_code) || zeros_only?(phone_number)
|
||||
if zeros_only?(country_code) || zeros_only?(subscriber_no)
|
||||
record.errors.add(attribute, :invalid)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue