1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| Public Shared Function GetPhoneNumber(ByVal PhoneNumber As String, Optional ByVal Format As PhoneFormat = PhoneFormat.International) As Integer
Dim i As Integer
Dim str As String
If Format = PhoneFormat.FrenchWithZero Then Throw New Exception("You can't convert french number with zero into integer format")
Dim BasicNumber As String = ""
Dim pfx As String = ""
For i = 0 To PhoneNumber.Length - 1
If Asc(PhoneNumber.Chars(i)) >= 48 And Asc(PhoneNumber.Chars(i)) <= 57 Then
str += PhoneNumber.Chars(i)
End If
Next
If PhoneNumber.Length < 8 Then Throw New Exception("Phone number is not valid!")
PhoneNumber = str
BasicNumber = PhoneNumber.Substring(str.Length - 8, 8)
str = BasicNumber
If PhoneNumber.Length = 8 Then
str = str.Insert(0, "1")
Else
pfx = PhoneNumber.Substring(PhoneNumber.Length - 9, 1)
str = str.Insert(0, pfx)
End If
If Format = PhoneFormat.International Then str = str.Insert(0, "33")
If Format = PhoneFormat.FrenchWithZero Then str = str.Insert(0, "0")
Return str
End Function |
Partager