Refactor contact phone validation

#569
This commit is contained in:
Artur Beljajev 2017-08-05 19:21:32 +03:00
parent 9e8f806a43
commit 71b92afba3
2 changed files with 6 additions and 6 deletions

View file

@ -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