Removing parenthesis and dashes from phone numbers

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Removing parenthesis and dashes from phone numbers

  • Creator
    Topic
  • #48792
    Ariba Jones
    Participant

      I have been asked to remove the parentheses and dashes from all occurrences of a telephone number and to remove the dashes from all occurrences of a ssn in the ADT messages going out to a system.  I have an xlate in place where I remove the dashes from the ssn in three segments.  This works fine.  

      Now that I need to remove the dashes from all occurrences of the ssn in the message, I am wondering if there is a way to do this without having to setup a COPY statement for each occurrence of the ssn.  This would mean I would have to identify each possible field that a ssn occurs in order to perform the COPY.  I currently have a short tcl proc attached in my COPY statement to do this.

      Removing the parenthesis and dashes from the telephone numbers is a challenge for me also.  I don’t know how to check for this, using a xlate, to identify only phone numbers and then remove the parenthesis and dashes.  Does anyone know how to do this?

      Thanks for your help in advance.

      Ariba

    Viewing 19 reply threads
    • Author
      Replies
      • #59688
        Charlie Bursell
        Participant

          It would be much safer to it on a field by field basis.  If done that way:

          set phoneNo [string map “( {} } {} – {}” $phoneNum]

          set ssan [string map “- {}” $ssan]

          If you want to take a chance that the patterns occur only in SSN and Phone numbers, you could do a proc like

          # replace all pattern (###)###-##### with ##########

          regsub -all — {((d{3}))(d{3})-(d{4})} $phoneNum {123} newNum

          # replace all pattern ###-##-#### with #########

          regsub -all — {(d{3})-(d{2})-(d{4})} $ssn {123} newSSN

        • #59689
          Ariba Jones
          Participant

            Charlie,

            The suggestion you give me to do it on a field-by-field basis is something that I have to put in a tcl proc, right?  If so, is this all that I would put in this proc?

            Are you saying that this would be done on a field-by-field basis for every field in the message or every phone number or ssn field I identify in the messages?

            I am trying to understand this.

            Thanks,

            Ariba

          • #59690
            Charlie Bursell
            Participant

              If I were going to do a lot of these I would put it in an external Xlate prov and just call it each time

              The phone number, for example:

              set phoneNo [lindex $xlateInVa

              set xlateOutVals

                ]

                That’s all there is to it

              1. #59691
                Ariba Jones
                Participant

                  Ok, Charlie.  I am trying to follow you here.  Forgive me for my “stupid” questions.  I am pretty new to doing all of this “manipulation” on the engine.  I haven’t had to do things like this (or any manipulation, really) until this project I am currently working on.  Please have patience with me when I ask you questions.

                  I think you are telling me that I could have a tcl proc with just those lines of code you indicate (in your last email) to remove the parenthesis and dashes from any occurrence of telephone numbers in the ADT message.  Is that correct?

                  Would I have something like this as a proc?

                  proc phone-noparenth  {}  {

                    set phoneNo [lindex $xlateInVa

                    set xlateOutVals

                    ]

                    }

                    Or would I have something like this to take care of both the phone number and ssn?

                    proc ssnph_nodash   {}  {

                      set phoneNo [string map “( {} } {} – {}” $phoneNum]

                      set ssan [string map “- {}” $ssan]

                    }

                    I am just trying to figure out how I need to setup the TCL proc since I have never written one of these before.

                    Thanks,

                    Ariba

                  1. #59692
                    Dave Zibble
                    Participant

                      There was a small but significant typo in the example.  The right parens in the first parameter was mistyped as a }.

                      You can do it Ariba!!  It works like a charm!  

                      tcl>set a (630)555-1212                          

                      tcl>set b [string map “( {} ) {} – {}” $a]      

                      tcl>echo $b

                      6305551212

                    • #59693
                      Ariba Jones
                      Participant

                        This is my tcl proc.

                      • #59694
                        Chris Williams
                        Participant

                          Your problem now is the spaces in the pattern.

                          You have written:

                          set xlateOutVals

                            ]

                            The pattern is a list of items in pairs. This one means translate:

                            (   to   {}

                            )   to   {}

                            –   to   {}

                          1. #59695
                            Charlie Bursell
                            Participant

                              Thanks for straightening this out for me.  I have been *REALLY* busy the last couple of days or I would have responded.

                              Charlie

                            • #59696
                              Ariba Jones
                              Participant

                                Chris,

                                I changed my tcl proc to look like you indicated, excluding the extra spaces, of course.  I get a different error now.  It looks like the variable xlateInVals is not recognized.

                                This is what my proc looks like now.

                                proc phone_nodash {} {

                                     

                                           set phoneNo [lindex $xlateInVals]

                                           set xlateOutVals

                                  ]

                                  }

                                  **Notice that I changed what I originally had as $phoneNum to $xlateInVals as you had in your response.

                                  This is the error I get when I run my xlate through the Testing Tool.

                                  errorInfo:

                                  can’t read “xlateInVals”: no such variable

                                    while executing

                                  “lindex $xlateInVals”

                                    (procedure “phone_nodash” line 5)

                                    invoked from within

                                  “phone_nodash”

                                  Thanks,

                                  Ariba

                                1. #59697
                                  Chris Williams
                                  Participant

                                    Sorry.

                                    set xlateOutVals  

                                      ]

                                      You might want to look for a good book on tcl/tk to have on hand as a reference. I think you would find your work a lot easier once you have a better understanding of tcl syntax. The Sam’s “Teach Yourself” series is good, as are a number of others.

                                    1. #59698
                                      Ariba Jones
                                      Participant

                                        Thanks, Chris. I will make the change and try again.

                                        I do have a Tcl and Tk book. I just haven’t had time to sit and go through it.  I have been so involved in this project.  I do try to look through this book for syntax questions, but sometimes that is hard for me because  I don’t know what I am doing here.

                                        Thanks,

                                        Ariba

                                      • #59699
                                        Ariba Jones
                                        Participant

                                          I have tried to test this proc again using my xlate.  I am getting the same error message.

                                          can’t read “xlateInVals”: no such variable

                                             while executing

                                          “lindex $xlateInVals”

                                              (procedure “phone_nodash” line 5)

                                               invoked from within

                                          “phone_nodash”

                                          I put $phoneNum back in the second set line of my proc and I still get this message.  I have pulled out the Tcl book I have to check the syntax for this.  It looks right.  I don’t know what else to do here.

                                          Any suggestions?

                                          Thanks,

                                          Ariba

                                        • #59700
                                          Michael Hertel
                                          Participant

                                            Hi,

                                            Cut and paste this:

                                            proc nodash_noparen {} {

                                          • #59701
                                            Ariba Jones
                                            Participant

                                              Michael,

                                              I copied and pasted this proc and tried using it to test my xlate.

                                              This is the message I receive.

                                              errorInfo:

                                              wrong # args: should be “upvar  ?level?  otherVar  localVar  ?otherVar

                                              localVar …?”

                                                 while executing

                                              “upvar xlateId              xlateId             “

                                                  (procedure “nodash_noparen”  line 2)

                                                  invoked from within

                                              “nodash_noparen”

                                              Should I have to specify args for this somewhere?

                                              Thanks,

                                              Ariba

                                            • #59702
                                              Michael Hertel
                                              Participant

                                                There were some extra spaces at the end of each line.

                                                I re-edited the post above.

                                                Please re-cut and paste it to see if it works.

                                                Thanks,

                                                -mh

                                              • #59703
                                                Ariba Jones
                                                Participant

                                                  Michael,

                                                  I get the same error message after doing this again.

                                                  Should there be only one space at the end of each line?  It looks like there may be two spaces at the end of each line when I look at the proc in the Script Editor.

                                                  Thanks,

                                                  Ariba

                                                • #59704
                                                  Michael Hertel
                                                  Participant

                                                    There should be no spaces after the characters.

                                                  • #59705
                                                    Ariba Jones
                                                    Participant

                                                      OK.  I will manually remove the extra spaces after the and let you know what happens in a minute.

                                                      Thanks,

                                                      Ariba

                                                    • #59706
                                                      Ariba Jones
                                                      Participant

                                                        Michael, you’re the best!!!!  It works now! I see the parenthesis and dash removed from the field I had this proc attached to in my xlate.  I just have to attach this proc to every field that I know is a phone number field.  Thanks so much!  You have made my day…………even better, I think you have made my WEEK!!!

                                                        Thanks,

                                                        Ariba

                                                      • #59707
                                                        Michael Hertel
                                                        Participant

                                                          You’re welcome.. 😀

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