ruby - phone-number
This commit is contained in:
parent
1eb8eb0e30
commit
fdb0f51e58
@ -1,19 +1,9 @@
|
|||||||
|
# PhoneNumber class
|
||||||
class PhoneNumber
|
class PhoneNumber
|
||||||
def self.clean(number)
|
def self.clean(number)
|
||||||
number.gsub!(/[^0-9]/, '')
|
number = number.gsub(/\D/, '').sub(/^[01]/, '')
|
||||||
|
return nil if number.length != 10 || %w[0 1].include?(number[3])
|
||||||
|
|
||||||
if number.length < 10 or number.length > 11
|
|
||||||
nil
|
|
||||||
elsif number.length == 11
|
|
||||||
if number[0] == "1"
|
|
||||||
number.slice(1, number.length)
|
|
||||||
else
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
elsif ["0", "1"].include?(number[0]) or ["0", "1"].include?(number[3])
|
|
||||||
nil
|
|
||||||
else
|
|
||||||
number
|
number
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user