phone format

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf phone format

  • Creator
    Topic
  • #52093
    Gary Atkinson
    Participant

      I want a phone field to always be in the format of (XXX)XXX-XXXX.  Anyone have a tcl snippet that does this that I could put in my HL7 translation?

    Viewing 2 reply threads
    • Author
      Replies
      • #73040

        Developing the code …

        Code:

        set pn “573-999-2640”
        #set pn “(573)999-2640”
        #set pn “573.999.2640”
        #set pn “573 999 2640″

        # Remove non-numeric characters
        set pn [string map {- {} ( {} ) {} . {} ” ” {}} $pn]

        # Format the phone number
        regsub {(d{3,3})(d{3,3})(d{4,4})} $pn {(1)2-3} pn

        puts $pn

        Testing an xlate environment …

        Code:

        lappend xlateInVals “573-999-2640”
        #lappend xlateInVals “573 999 2640″
        set pn [string map {- {} ( {} ) {} . {} ” ” {}} [lindex $xlateInVals 0]]
        regsub {(d{3,3})(d{3,3})(d{4,4})} $pn {(1)2-3} pn
        set xlateOutVals [list $pn]
        puts [lindex $xlateOutVals 0]

        Fragment for the xlate …

        Code:

        set pn [string map {- {} ( {} ) {} . {} ” ” {}} [lindex $xlateInVals 0]]
        regsub {(d{3,3})(d{3,3})(d{4,4})} $pn {(1)2-3} pn
        set xlateOutVals [list $pn]

        -- Max Drown (Infor)

      • #73041
        Charlie Bursell
        Participant

          If you assume an all number input I would do something like

          set num [lindex $xlateInVals

          regsub — {^(d{3})(d{3})(d{4})$} $num {(1)2-3} num

          set xlateOutVals

            Note that if the input is not exactly 10 digits it is left as-is

        • #73042
          Gary Atkinson
          Participant

            thx guys

        Viewing 2 reply threads
        • The forum ‘Cloverleaf’ is closed to new topics and replies.