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) 

devx-admin

Share the Post: