0

Phone Number Formatting?

When typing a phone number in the phone number field (or even text field, whichever is possible), how do I set an automatic phone number format? I would like my format to be (555) 555-5555. 

30 replies

null
    • Sean
    • 4 yrs ago
    • Reported - view

    I don't think that is possible.

    • Sean
    • 4 yrs ago
    • Reported - view

    I made some changes to your code. Hope you don't mind...

     

    let sym := "+";
    let pad := "#";
    let digits := replacex(Phone, "\D", "g", "");
    let ln := length(digits);
    let pre := if ln - 10 > 0 then ln - 10 else 0 end;
    let split := "(.{" + pre + "})(.{3})(.{3})(.)";
    if pre < 1 then sym := "" end;
    let format := sym + "$1 ($2) $3-$4";
    if ln < 10 then
    digits := lpad(digits, 10, pad)
    end;
    Phone := replacex(digits, split, "", format)

    • Ben.2
    • 4 yrs ago
    • Reported - view

    Cool! Looks great , and I definitely don't mind. It definitely feels more clean, this way and I like the # substitution. After playing with many ways to reference the field name with a variable, I basically figured it was not possible. But considering that I also thought that filtering a text by character type wasn't possible, I figured it's best to ask outright

    • Ben.2
    • 4 yrs ago
    • Reported - view

    I'm wondering if its possible to put this in a trigger after update for the table, modified so that it checks/reformats the entire field

    • Ben.2
    • 4 yrs ago
    • Reported - view

    well, it seems like I just answered my question. I put the following in the TABLE "trigger after update" of a test table with a bunch of unformatted numbers and updated one cell, and it formatted all of them correctly as phone numbers:

    let sym := "+";
    let pad := "x";
    for i in select Table do
    let digits := replacex(i.Phone, "\D", "g", "");
    let ln := length(digits);
    let pre := ln - 10;
    let split := "(\d{" + pre + "})(\d{3})(\d{3})(\d)";
    if pre < 1 then sym := "" end;
    let format := sym + "$1 ($2) $3-$4";
    if ln < 10 then
    i.(Phone := rpad(i.Phone, 10, pad))
    else
    i.(Phone := replacex(digits, split, "", format))
    end
    end

    My code is still a tad different from yours Sean, but thats just because I haven't looked carefully to see what you changed at the end. I have no doubts that yours is a bit more streamlined.

Content aside

  • 4 yrs agoLast active
  • 30Replies
  • 8300Views