Friday 16 May 2014

Validate Phone number

 Shared Function removestdextra(ByVal phoneno As String, Optional ByVal stdcode As String = "", Optional ByVal compphno As String = "") As String
        If phoneno = "" Or phoneno Is Nothing Then Exit Function
        While phoneno.ToUpper.Contains("EXT") = True
            Dim expos = InStr(phoneno.ToUpper, "EXT")
            Dim expi = Mid(phoneno, expos, Len(phoneno))
            Dim expose1 = InStr(expi, ",")
            If expose1 = 0 Then expose1 = Len(expi) + 1
            phoneno = Replace(phoneno, Mid(phoneno, expos, expose1), ",")
        End While
        phoneno = Replace(phoneno.ToUpper, "+91", "")
        phoneno = phoneno.Replace("-", ",").Replace("/", ",")
        Dim newphoneno(Len(phoneno)) As String
        Dim j As Integer = 0
        For inct As Integer = 1 To Len(phoneno)
            If IsNumeric(Mid(phoneno, inct, 1)) Then
                newphoneno(j) = Mid(phoneno, inct, 1).Trim
                j = j + 1
            ElseIf Mid(phoneno, inct, 1) = "," Then
                newphoneno(j) = Mid(phoneno, inct, 1).Trim
                j = j + 1
            End If
        Next
        phoneno = Join(newphoneno, "")
        If phoneno.Contains("123456") Then phoneno = ""
        Dim extractno As String = ""
        Dim newvalid As String = ""
        newvalid = phoneno.Replace("-", ",").Replace("/", ",")
        Dim abc() As String
        abc = newvalid.Split(",")
        removestdextra = compphno
        Dim actualph As String = ""
        Dim lstno As String = ""
        Dim newno As String = ""
        For icnt As Integer = 0 To abc.Length - 1
            If abc(icnt).StartsWith(stdcode) And stdcode <> "" Then
                actualph = Val(Replace(abc(icnt), stdcode, "", 1).Trim)
            Else
                actualph = Val(abc(icnt))
            End If
            If Len(actualph) >= 6 Then
                extractno = validintergerphne(actualph).Trim
                If removestdextra = "" And extractno <> "" Then
                    removestdextra = extractno
                ElseIf removestdextra <> "" And extractno <> "" And InStr(removestdextra, extractno) = 0 Then
                    removestdextra = removestdextra & "," & extractno
                End If
            ElseIf Len(actualph) = 2 And icnt >= 1 And removestdextra <> "" And extractno <> "" Then
                If removestdextra <> "" Then
                    removestdextra = removestdextra & "," & Mid(extractno, 1, Len(extractno) - 2) & abc(icnt)
                End If
            ElseIf Len(actualph) = 3 And icnt >= 1 And removestdextra <> "" And extractno <> "" Then
                If removestdextra <> "" Then
                    removestdextra = removestdextra & "," & Mid(extractno, 1, Len(extractno) - 3) & abc(icnt)
                End If
            End If
        Next
        Return removestdextra
    End Function
=============================

   Shared Function validintergerphne(ByVal phno As String) As String
        validintergerphne = ""
        Dim newno As String = ""
        For validi As Integer = 1 To Len(phno)
            newno = Mid(phno, validi, 1)
            If IsNumeric(newno) Then
                validintergerphne = validintergerphne & newno
            End If
        Next
        If Len(validintergerphne) < 6 Then
            validintergerphne = ""
        ElseIf Val(validintergerphne) = 0 Then
            validintergerphne = ""
        End If
    End Function

Followers