Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Clean up messy phone no format function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Clean up messy phone no format function

    This function will take junky phone numbers and properly format them (assuming the input contains 7 digits):

    ''e.g. If vMask=0 ===> "123-456(78.9.0" ===> "1234567890"
    ''e.g. If vMask=1 ===> "123-456(78.9.0" ===> "123-456-7890"
    Code:
    'Date Created: 13-Jan-2005 11:04:47 AM
    'Last Updated: 30-Aug-2005 02:27:44 PM
    'Created By  : PG
    'Updated By  : PG
    
    FUNCTION funcPhoneTransform AS C (vPhoneNo as C, vMask=0 as N )
        ''Transform a phone no by stripping out non-alpha/non-numeric characters
        ''Thus allowing pasting of odd phone nos into a phone_no field w. a mask
            ''e.g. If vMask=0 ===> "123-456(78.9.0" ===> "1234567890"
            ''e.g. If vMask=1 ===> "123-456(78.9.0" ===> "123-456-7890"
        
        Dim vPhoneNo as C
        Dim vPhoneNo2 as C
        vPhoneNo = ALLTRIM(Remspecial(vPhoneNo))
        
        vLen = LEN(vPhoneNo)
        FOR i = 1 TO vLen
            IF isdigit(substr(vPhoneNo,i,1)) = .t.
                vPhoneNo2 = vPhoneNo2 + substr(vPhoneNo,i,1)
            END IF
        next
        vPhoneNo = vPhoneNo2
    
        IF vMask=0
            funcPhoneTransform = vPhoneNo
        ELSE IF    vMask=1
            vPhoneNo = Left(vPhoneNo,3) + "-" + substr(vPhoneNo,4,3) + "-" + right(vPhoneNo,4)
            funcPhoneTransform = vPhoneNo        
        END IF
    END FUNCTION
    Peter
    AlphaBase Solutions, LLC

    [email protected]
    https://www.alphabasesolutions.com



    #2
    This one includes standard phone no format with parenthesis.

    i.e.

    "123-456(78.9.0" ===> "(123) 456-7890"
    Peter
    AlphaBase Solutions, LLC

    [email protected]
    https://www.alphabasesolutions.com


    Comment


      #3
      Hi Peter,

      This is my older one. While a bit different from yours, it is maybe a bit more adaptable for other people's needs.

      I've attached the script file as well for easy download.


      Code:
      'Date Created: 09-Apr-1999 11:01:19 AM
      'Last Updated: 28-Jan-2006 06:25:48 PM
      'Created By  : Ira J. Perlow
      'Updated By  : Ira J. Perlow
      FUNCTION PhoneXlat AS C (PhoneNumber as C,TemplateMask="" as C,MaximumLength=10 as N,AreaCode="" as C)
      'DESCRIPTION: Convert phone # to a normalized format
      
      ' Copyright 1999 Computer Systems Design & Associates, All Rights Reserved
      
      ' Purpose: Convert phone # to a normalized format
      
      ' Input: PhoneNumber in any format, can include AlphaNumerics
      '                Leading 1 is removed if present
      '         TemplateMask = Format to transform phone number into.  Default's to Null
      '                9 is replaced by a digit, all other characters are used as is
      '                If null, then uses format 999-999-9999.
      '                If blank but not null, then uses format (999)999-9999
      '         MaximumLength is maximum number of phone digits allowed 
      '                Default is 10
      '                (typically if phone number is in alphanumerics, extra characters after length are ignored)
      '         AreaCode is default area code if number length is exactly 7.  default is 3 spaces
      
      ' Output:Phone # in new format converted to numeric string with template characters in it
      
      ' Errors:
                  
      ' Typical Usage:
      
      ' Examples:
      '        ?PhoneXlat("(234)-567-8901")
      '        ?phonexlat("234-567-ALPHA")
      '        ?phonexlat("1-234-567-ALPHA")
      '        ?phonexlat("234-567-ALPHA"," ")
      '        ?phonexlat("234-567-ALPHA","999.999.9999",10,"781")
      '        ?phonexlat("234-567-ALPHA","(999) 999-9999",10,"781")
      '        ?phonexlat("567-CSDA","(999) 999-9999",10,"781")
      '        ?phonexlat("567-1234","(999) 999-9999",10,"781")
      
      
      ' Notes: None
      
      ' Set inital return value        
      PhoneXlat=""
      
      ' Delete all leading and trailing spaces and convert to uppercase
      phnum=UPPER(ALLTRIM(PhoneNumber))
      
      ' Convert all alphabetic's to numbers
      phnum=chrtran(phnum,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","22233344455566677778889999")
      
      ' See if it's a foreign phone number
      IF left(phnum,1)=="0"
          ' It's a foreign phone number, leave unchanged
          phnum=phnum
          END
      END IF
      
      ' Strip out non-numeric characters
      phnum=remspecial(phnum)
      
      ' If it is leading with a "1", get rid of it for standard format
      IF left(phnum,1)=="1"
          phnum=SUBSTR(phnum,2)
      END IF
      
      ' If only 7 characters long, add the area code in front
      IF len(phnum)=7
          ' Default area code is 3 blanks
          If areacode==""
              areacd="   "
          Else
              areacd=UPPER(ALLTRIM(areacode))
              areacd=chrtran(areacd,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","22233344455566677778889999")
          END IF
          phnum=areacd+phnum
      END IF
      
      IF len(phnum)>MaximumLength
          phnum=LEFT(phnum,MaximumLength)
      END IF
      
      If TemplateMask==""
          msk="999-999-9999"
      Else if trim(TemplateMask)="".and.len(TemplateMask)>0
          msk="(999)999-9999"
      else
          msk=TemplateMask
      end if
      
      phnuml=len(phnum)
      j=0
      ph=""
      
      For i=1 to len(msk)
          ch=substr(msk,i,1)
          IF ch="9"
              j=j+1
              IF j>phnuml
                  ph=ph+" "
              ELSE
                  ph=ph+substr(phnum,j,1)
              END IF
          ELSE
              ph=ph+substr(msk,i,1)
          END IF
      NEXT i
      
      PhoneXlat=ph
      
      END FUNCTION
      Regards,

      Ira J. Perlow
      Computer Systems Design


      CSDA A5 Products
      New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
      CSDA Barcode Functions

      CSDA Code Utility
      CSDA Screen Capture


      Comment


        #4
        Whenever I write a function, I think: "Now, what would Ira do?", then I say "nah, forget it!"
        Peter
        AlphaBase Solutions, LLC

        [email protected]
        https://www.alphabasesolutions.com


        Comment


          #5
          Originally posted by Peter G.
          Whenever I write a function, I think: "Now, what would Ira do?", then I say "nah, forget it!"
          Hi Peter,

          It’s just the way you look at it.

          Suppose someone writes "alphabetical numerics" such as “o” an “i” or a “l”
          Mostly they mean a zero or a one.
          If I am right, Ira in this case translates them to uppercase and changes O in 6, I in 4 and L in 5.
          For me this is unacceptable. (Sorry Ira, of course I like to see your great inventions. I always learn of your code.)

          To be sure that the input is all numeric I wrote the num_only function.
          In the Netherlands all the telephonenumbers are 10 digits so I also test the length of the result before accepting it.

          Just for fun an absurd example:

          Code:
          dim input as C
          dim output as N
          input = " - 9 7 hi PETER and IRA 6t rdgasdljkhq5';lk345K:f5.3 "
          output = num_only(input)
          ? output
          = 976534553
          Here is the function:
          Code:
          'Date Created: 01-Dec-2004 03:54:18 PM
          'Created By  : Ton Spies
          
          FUNCTION num_only AS N (input_string AS C )
          
          ' Numeric return of the numeric characters in the input_string
          num_only = val(chrtran(remspecial(lower(Input_String)),"abcdefghijklmnopqrstuvwxyz",""))
          
          END FUNCTION
          As you can see with remspecial (also) all spaces will be removed.

          Ton
          Last edited by AaronBBrown; 01-31-2006, 10:37 AM.
          Most things are simple but unfortunately only after the first time

          Comment


            #6
            Very succinct, Ton. Except you violate the "rule" that only fields used for math should be numeric.
            Peter
            AlphaBase Solutions, LLC

            [email protected]
            https://www.alphabasesolutions.com


            Comment


              #7
              Hi Ton,

              Originally posted by Ton Spies
              Suppose someone writes "alphabetical numerics" such as �o� an �i� or a �l�
              Mostly they mean a zero or a one.
              If I am right, Ira in this case translates them to uppercase and changes O in 6, I in 4 and L in 5.
              For me this is unacceptable. (Sorry Ira, of course I like to see your great inventions. I always learn of your code.)
              Obviously you can't always predict all needs for everyone, however, that doesn't mean you couldn't modify the code! Just putting in a length check and eliminating the translation would solve it.

              Originally posted by Ton Spies
              To be sure that the input is all numeric I wrote the num_only function.
              In the Netherlands all the telephonenumbers are 10 digits so I also test the length of the result before accepting it.

              Just for fun an absurd example:

              Code:
              dim input as C
              dim output as N
              input = " - 9 7 hi PETER and IRA 6t rdgasdljkhq5';lk345K:f5.3 "
              output = num_only(input)
              ? output
              = 976534553
              But the above number is only 9 characters! And making it a number, means any leading zeros are not seen. It may be true there are no domestic numbers that fall into having leading zeros, but other country codes do start with 0.

              But, I made a modification that will address your cases and have attached it as well

              Code:
              'Date Created: 09-Apr-1999 11:01:19 AM
              'Last Updated: 31-Jan-2006 01:39:41 PM
              'Created By  : Ira J. Perlow
              'Updated By  : Ira J. Perlow
              FUNCTION PhoneXlat AS C (PhoneNumber as C,TemplateMask="" as C,MaximumLength=10 as N,AreaCode="" as C,AlphaXlat=.T. as L,LengthCheck=0 as N)
              'DESCRIPTION: Convert phone # to a normalized format
              
              ' Copyright 1999 Computer Systems Design & Associates, All Rights Reserved
              
              ' Purpose: Convert phone # to a normalized format
              
              ' Input: PhoneNumber in any format, can include AlphaNumerics
              '                Leading 1 is removed if present
              '         TemplateMask = Format to transform phone number into.  Default's to Null
              '                9 is replaced by a digit, all other characters are used as is
              '                If null, then uses format 999-999-9999.
              '                If blank but not null, then uses format (999)999-9999
              '         MaximumLength is maximum number of phone digits allowed 
              '                Default is 10
              '                (typically if phone number is in alphanumerics, 
              '                 extra characters after length are ignored)
              '         AreaCode is default area code if number length is exactly 7.  
              '                default is 3 spaces
              '         AlphaXlat if .t. translate alphabetic to numeric
              '                    if .f. strips alphabetics out (in order to catch errors)
              '         LengthCheck    verify that phone digit length is exactly this long (without template)
              '                         0 implies any length is acceptable
              
              ' Output:Phone # in new format converted to numeric string with template characters in it
              
              ' Errors:
                          
              ' Typical Usage:
              
              ' Examples:
              '        ?PhoneXlat("(234)-567-8901")
              '        ?phonexlat("234-567-ALPHA")
              '        ?phonexlat("1-234-567-ALPHA")
              '        ?phonexlat("234-567-ALPHA"," ")
              '        ?phonexlat("234-567-ALPHA","999.999.9999",10,"781")
              '        ?phonexlat("234-567-ALPHA","(999) 999-9999",10,"781")
              '        ?phonexlat("234-567-ALPHA","999-999-9999",10,"781",.t.,0)
              '        ?phonexlat("234-567-ALPHA","999-999-9999",10,"781",.f.,0)
              '        ?phonexlat("234-567-ALPHA","999-999-9999",10,"781",.t.,10)
              '        ?phonexlat("234-567-ALPHA","999-999-9999",10,"781",.f.,10)
              '        ?phonexlat("234-567-ALPH","999-999-9999",10,"781",.t.,10)
              '        ?phonexlat("234-567-ALPH","999-999-9999",10,"781",.f.,10)
              '        ?phonexlat("567-CSDA","(999) 999-9999",10,"781")
              '        ?phonexlat("567-1234","(999) 999-9999",10,"781")
              
              
              ' Notes: None
              
              ' Set inital return value        
              PhoneXlat=""
              
              ' Delete all leading and trailing spaces and convert to uppercase
              phnum=UPPER(ALLTRIM(PhoneNumber))
              
              ' Convert all alphabetic's to numbers
              IF AlphaXlat=.T.
                  phnum=chrtran(phnum,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","22233344455566677778889999")
              ELSE
                  phnum=chrtran(phnum,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","~~~~~~~~~~~~~~~~~~~~~~~~~~")
              END IF
              
              ' See if it's a foreign phone number
              IF left(phnum,1)=="0"
                  ' It's a foreign phone number, leave unchanged
                  phnum=phnum
                  END
              END IF
              
              ' Strip out non-numeric characters
              phnum=remspecial(phnum)
              
              ' If it is leading with a "1", get rid of it for standard format
              IF left(phnum,1)=="1"
                  phnum=SUBSTR(phnum,2)
              END IF
              
              ' If only 7 characters long, add the area code in front
              IF len(phnum)=7
                  ' Default area code is 3 blanks
                  If areacode==""
                      areacd="   "
                      phnum=areacd+phnum
                  Else
                      areacd=UPPER(ALLTRIM(areacode))
                      IF AlphaXlat=.T.
                          areacd=chrtran(areacd,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","22233344455566677778889999")
                      ELSE
                          areacd=chrtran(areacd,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","~~~~~~~~~~~~~~~~~~~~~~~~~~")
                      END IF
                      phnum=remspecial(areacd+phnum)
                  END IF
              END IF
              
              If TemplateMask==""
                  msk="999-999-9999"
              Else if trim(TemplateMask)="".and.len(TemplateMask)>0
                  msk="(999)999-9999"
              else
                  msk=TemplateMask
              end if
              
              IF LengthCheck>0
                  IF len(phnum)<>LengthCheck
                      ' Not valid length, so output blank template
                      PhoneXlat=chrtran(msk,"9"," ")
                      END
                  END IF
              END IF
              
              ' If we exceed the maximum length
              ' generally either a typo or a long alphabetic where trailing 
              ' characters don't matter, then trim it off
              IF len(phnum)>MaximumLength
                  phnum=LEFT(phnum,MaximumLength)
              END IF
              
              phnuml=len(phnum)
              ' j hold's pointer to phone number digits
              j=0
              
              ' k hold's number of digits processed (does not count alphabetic or spaces)
              k=0
              
              ' ph hold's the phone number with template being built
              ph=""
              
              For i=1 to len(msk)
                  ' Get i'th character of template
                  ch=substr(msk,i,1)
              
                  IF ch="9"
                      ' If template is a "9", then place a phone digit into that postion
                      ' get next phone digit
                      j=j+1
                      IF j>phnuml
                          ' If out of digits, then add spaces at end
                          ph=ph+" "
                      ELSE
                          ' If digit, then add it in
                          IF substr(phnum,j,1) $ "0123456789"
                              ' Increment digit count
                              k=k+1
                              ph=ph+substr(phnum,j,1)
                          END IF
                      END IF
                  ELSE
                      ' add template character in
                      ph=ph+substr(msk,i,1)
                  END IF
              
              NEXT i
              
              PhoneXlat=ph
              
              END FUNCTION
              So for your needs, the function call would be

              ?phonexlat("234-567-8901","999-999-9999",10,"",.f.,10)
              Regards,

              Ira J. Perlow
              Computer Systems Design


              CSDA A5 Products
              New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
              CSDA Barcode Functions

              CSDA Code Utility
              CSDA Screen Capture


              Comment


                #8
                A small error in the above

                Code:
                ' It's a foreign phone number, leave unchanged
                    phnum=phnum
                should have been

                Code:
                ' It's a foreign phone number, leave unchanged
                    PhoneXlat=phnum

                I have attached the updated version as well.
                Regards,

                Ira J. Perlow
                Computer Systems Design


                CSDA A5 Products
                New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
                CSDA Barcode Functions

                CSDA Code Utility
                CSDA Screen Capture


                Comment

                Working...
                X