Parsing a phone number out of a text block
I am trying to parse out the below bold phone number from this text block that comes in from a call line of ours... I want to input it into its own field using Podio Calculation. Anyone have any ideas how to extract that phone number and do this??? Thanks.
---------------------------------------
Voice message sent to (888) 262-0619 mailbox 81 ext 127 at 9:28:21 AM on
2/24/2016 from (928) 399-9853.
This message appears to be a hang up.
LPP
Prop Signage
---------------------------------------
-
Hi Scott,
if there's always the word "from" in front of the number and always a dot behind it you can pull the number this way (there are several ways)
var text = @Text
var preIndex = text.indexOf("from ")
var searchIndex = preIndex + text.substring(preIndex).indexOf(".")
text.substr(preIndex,(searchIndex-preIndex)).replace(/[^-0-9() ]/g,"")Result is: (928) 399-9853
Instead of "." in the var searchindex you can also use "\n"
The part .replace() is only necessary to get rid of the markdown signs** if the number is bold and the dot (if you use "n"). If you want a pure number use .replace(/[^0-9]/g,""). That deletes ()- and space too.
What do you mean by: "I want to input it into its own field using Podio Calculation"? You can only show it in a calculation field. If you want to input in a text field "Phone" or a phone field you need Globiflow. But GF can't be triggered directly by a change of the calculation field. You would need the Podio Advanced Flows too. A flow like:
IF item has been updated in the calculation field create a comment "PHONE EXTRACTED" and then a GF triggered by a new comment.
I assume, this text comes in via E-Mail. If you can decide how the message text looks like, ask the sender if he could change the message to:Voice message sent to (888) 262-0619 mailbox 81 ext 127 at 9:28:21 AM on
2/24/2016 fromPhone: (928) 399-9853
This message appears to be a hang up.
LPP
Prop Signage
If you have a text field "Phone" Podio will map it, so that the phone number will be entered into the field Phone, when the E-Mail body is copied into the existing text field.
Rainer
-
Hi Rainer, Thank you again for your calculation prowess!
I mis-typed when I said, "I want to input it into its own field using Podio Calculation". Disregard, I know it needs to be in a calculation field - not sure what I was thinking when I wrote that. Can't wait to try this code. Thanks as always!
-
here is the text
Besteller: Name: Test 1E-Mail: test@test.deTelefon: 089418560562Anschrift: Straße Die Bestellung: wird abgeholtoder Bestellung eingeben:
Problem also "Telefon" must also be deleted so that I get the plane email adress
-
Hi Markus,
in your example "Telefon" is part of the (linked) Mail-Address. If this can't happen in "real life" (in the text you get)
you can use this:
var a = @Text;
a.slice(a.indexOf("Mail:")+5,a.indexOf("Telefon"))If it can happen:
var a = @Text;
var b = a.slice(a.indexOf("Mail:")+5,a.indexOf("Telefon")).replace(/[\[\]\(\) ]/g,"");
"<" + b + ">"This only works, if the syntax is always the same: Mail: directly in front of the mail-address and Telefon directly after it.
Hope it helps,
Rainer
rg@delos-consulting.com -
Hi Gus,
that code was made exactly for the format in Scott's question. It doesn't work for you cause there are line breaks in your text field.
Here's a more general code which works for evey text format, but only if in text always are:
2 phone numbers in it (you want the second one) and these phone numbers have the format:
left parenthesis (
3 digits
right parenthesis )
space
3 digits
dash -
4 digitsThe code:
var a = @Details of the call;
var pattern = /(\(\d{3}\)\s\d{3}\-\d{4})/g;
try {
a.match(pattern)[1];
} catch(e) {
"Error"
};Rainer
-
Hi Rainer, I hope you are well. I'm hoping you have another trick up your sleeve with parsing phone #s. I want to be able to take a phone number and strip out anything that is not a number.
Example:
(555) 555-5555 or 555-555-5555 or 555.555.5555 or 555 555 5555 (or other variants) should all end up looking like "5555555555". I need to strip the symbols out so I can use it to send sms's out via GlobiFlow. Any help you can offer is, as always, greatly appreciated. Thanks - Scott
Please sign in to leave a comment.
Comments
13 comments