mirror of
https://github.com/internetee/registry.git
synced 2025-07-01 08:43:37 +02:00
parent
9a6f5939c4
commit
bacf5f8d64
6 changed files with 152 additions and 12 deletions
19
lib/validators/phone_validator.rb
Normal file
19
lib/validators/phone_validator.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
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
|
||||
|
||||
if zeros_only?(country_code) || zeros_only?(phone_number)
|
||||
record.errors.add(attribute, :invalid)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def zeros_only?(value)
|
||||
value.delete('0+').empty?
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue