Calculation to Change Numbers to a Phone Number Format

Comments

6 comments

  • Rainer Grabowski

    Hi Joshua,

    this is the code if @Phone Number 3 is a text field. 

    var phone = @Phone Number 3;
    var cleanPhone = phone.replace(/[^0-9]/g,"");
    cleanPhone.replace(/(\d{3})(\d{3})(\d{4})/,"($1)-$2-$3")

    If it is a Phone field:

    var phone = @Phone Number 3;
    var phone = phone.map(function (i){return i.value}).join();
    var cleanPhone = phone.replace(/[^0-9]/g,"");
    cleanPhone.replace(/(\d{3})(\d{3})(\d{4})/,"($1)-$2-$3")

    Rainer

    1
    Comment actions Permalink
  • Operations Team

    Hello Rainer, thank you for this! I tried it, but I get an error.

    0
    Comment actions Permalink
  • Operations Team

    The phone number is in a text field.

    0
    Comment actions Permalink
  • Rainer Grabowski

    Ignore that error notification. Just save the template. If you can't save it add a new calculation field and enter @Unique ID (and pick the token). Save it. Come back and add the phone number code (and remove the @unique id token).

    0
    Comment actions Permalink
  • Andrew Booth

    Hi Rainer Grabowski thank you for all the help you have given in the forum. Has helped me a ton sort out different problems.

    Though I am still have a problem with this one, I used your formula referencing to phone number in text value.

    It is not returning a number when looking at from normal view, any insight why.?

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Andrew,
    I think, the problem is the sometimes weird behaviour of the calculation field. 
    Check the type of the calculation field (click the littel triangle on the left side, I bet it was saved as a number field). If so, under your code add "x" (x with quotation marks), save, open the template, remove the "x", save. 
    The type shoild be text now and it should show the formatted number in normale view. 
    If not: Add a new calculation field and enter @Unique ID (and pick the token). Save it. Come back and add the phone number code (and remove the @unique id token).
    Rainer

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk