forked from anthonyto/anonymous-twilio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestPhoneNumbers.rb
40 lines (38 loc) · 990 Bytes
/
TestPhoneNumbers.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def extract_phone_number(input)
firstCharIndex = input =~ /[a-zA-Z#]/
number = input[0..firstCharIndex-1]
return clean_phone_number(number)
end
def clean_phone_number(input)
if input.gsub(/\D/, "").match(/^1?(\d{3})(\d{3})(\d{4})/)
[$1, $2, $3].join()
end
end
#
# body = "1 (858)229-5512 Something something dskfdl"
# puts extract_phone_number(body)
# puts body
# puts
# body = "18582295512 Something something dskfdl"
# puts body
# puts extract_phone_number(body)
# puts
# body = "+18582295512 Something something dskfdl"
# puts body
# puts extract_phone_number(body)
# puts
# body = "1(858)229-5512 Something something dskfdl"
# puts body
# puts extract_phone_number(body)
# puts
# body = "1(858) 229 5512 Something something dskfdl"
# puts body
# puts extract_phone_number(body)
# puts
# body = "#1(858) 229 5512 Something something dskfdl"
# puts body
# puts extract_phone_number(body).length
# puts
body = "517 573 2345 blah blahs"
body.slice! /^\S+/
puts body