Avatar billede bendixen Novice
09. september 2003 - 21:15 Der er 1 løsning

Validering af IP adr

Jeg skal bruge en funktion der kontrolerer om man har indtastet en gyldig ipadr i en textbox
Avatar billede bendixen Novice
09. september 2003 - 21:36 #1
'**************************************
' Name: Function to test for a valid IP
'    Address
' Description:This function will return
'    True if the passed value is a valid IP A
'    ddress. I basically made this for my DNS
'    Hostname DLL I was working on so that I
'    could use just one method. Works REALLY
'    fast.
' By: _maniac_
'
' Inputs:Host As String
'
' Returns:True if the Host is a valid IP
'    Address, False if not.
'


Public Function IsIPAddress(Host As String) As Boolean
   
    'Quick length test
    If Len(Host) > 15 Or Len(Host) < 7 Then
        'Host is longer or shorter than possible IP
        IsIPAddress = False
        Exit Function
    End If
   
    'Split components between periods
    Dim tmpParts() As String
    Dim i As Integer
    tmpParts = Split(Host, ".")
   
    'Check number of components
    If UBound(tmpParts) <> 3 Then
        'Not correct numbers of periods/components
        IsIPAddress = False
        Exit Function
    Else
        'Follows IP format - Check each component
        For i = 1 To UBound(tmpParts)
            If IsNumeric(tmpParts(i)) = False Or Len(tmpParts(i)) > 3 Then
                'Non-numeric or too long
                IsIPAddress = False
                Exit Function
            Else
                'Test value
                If CInt(tmpParts(i)) > 255 Then
                    'Value too large
                    IsIPAddress = False
                    Exit Function
                End If
            End If
        Next
    End If
   
    'Passed all tests
    IsIPAddress = True
End Function

Fandt denne
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester