devxlogo

FormatPhoneNumber – Format a phone number

FormatPhoneNumber – Format a phone number

' Modify a phone-number to the format "XXX-XXXX" or "(XXX) XXX-XXXX".Function FormatPhoneNumber(ByVal text As String) As String    Dim i As Long        ' ignore empty strings    If Len(text) = 0 Then Exit Function        ' get rid of dashes and invalid chars    For i = Len(text) To 1 Step -1        If InStr("0123456789", Mid$(text, i, 1)) = 0 Then            text = Left$(text, i - 1) & Mid$(text, i + 1)        End If    Next    ' then, re-insert them in the correct position    If Len(text) 

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist