/ Published in: Visual Basic
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
Function formatPhoneNbr(PhoneNbrStr As String) As String
Dim tmpNbr As String
Dim tmpPos As String
Dim tmpLen As Byte
Dim i As Byte
' Get all numbers
For i = 1 To Len(PhoneNbrStr)
tmpPos = Mid(PhoneNbrStr, i, 1)
If IsNumeric(tmpPos) Then
tmpNbr = tmpNbr & tmpPos
End If
Next i
' Get phone number length
tmpLen = Len(tmpNbr)
' Output formatted phone number
Select Case tmpLen
Case 7 ' No area code
formatPhoneNbr = Left(tmpNbr, 3) & "-" & Right(tmpNbr, 4)
Case 10 ' Include area code
formatPhoneNbr = "(" & Left(tmpNbr, 3) & ") " & _
Mid(tmpNbr, 4, 3) & "-" & Right(tmpNbr, 4)
Case Else
formatPhoneNbr = "Invalid Phone Number"
End Select
End Function
Comments
 Subscribe to comments
                    Subscribe to comments
                
                