Parsing a phone number out of a text block

Comments

13 comments

  • Rainer Grabowski

    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 from

    Phone: (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

    0
    Comment actions Permalink
  • Jean-Claude Massé

    Is your message have always the same pattern? (at least for Voice message sent to (888) 262-0619 mailbox 81 ext 127 at 9:28:21 AM on
    2/24/2016 from (928) 399-9853.)

    0
    Comment actions Permalink
  • Scott Anderson

    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!

     

    0
    Comment actions Permalink
  • Scott Anderson

    Yes Jean-Claude Massé - the message pattern is always the same.  Thank you. 

    0
    Comment actions Permalink
  • Markus Fakler

    Hi Rainer,

    this is exactly what I´m looking for a email adress. I have a email adress in the text body and want to calculate, exactly as you did with the number but I don´t get it.

    Markus

    0
    Comment actions Permalink
  • Markus Fakler

    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

    0
    Comment actions Permalink
  • Rainer Grabowski

    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

    0
    Comment actions Permalink
  • Gus H.

    Hi Rainer. For some reason, mine is not working. :-( 

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Gus,

    you have a typo in the 2. line:
    it must be: indexOf 
    x before the O (you have: indesOf)


    Rainer

    0
    Comment actions Permalink
  • Gus H.

    Thanks Rainer. I need to order bigger glasses. But still no luck:

    0
    Comment actions Permalink
  • Rainer Grabowski

    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 digits 

    The 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

    0
    Comment actions Permalink
  • Gus H.

    Thank you. Works perfectly. As always: Solution, thy name is Rainer.....

    0
    Comment actions Permalink
  • Scott Anderson

    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

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk