Forum Discussion

Iamvinod's avatar
Iamvinod
Occasional Contributor
5 years ago

Format a series of number as a phone number

How Can I Format a Series of Numbers as a Phone Number in vbscript?

ex: 4206322623 as (420) 632-2623?

  • Use this very simple VBScript work,

    The trick is to use number as string and thus you can do your format quite easily.

     

    Function FormatPhone(str)
      FormatPhone = "(" + Left(str, 3) + ") " + Mid(str,4,3) + "-" + Right(str, 4)
    End Function 

     

     

    But this is assuming using only US centric fixed format.

    • BenoitB's avatar
      BenoitB
      Community Hero

      Use this very simple VBScript work,

      The trick is to use number as string and thus you can do your format quite easily.

       

      Function FormatPhone(str)
        FormatPhone = "(" + Left(str, 3) + ") " + Mid(str,4,3) + "-" + Right(str, 4)
      End Function 

       

       

      But this is assuming using only US centric fixed format.