VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



IsIP Function v2

by Daniel M (8 Submissions)
Category: Coding Standards
Compatability: VB Script
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

Updated version of IsIP function. Should clear up all the problems in the last one. Here ya go, =)

Rate IsIP Function v2

Private Function IsIP(strIP As String) As Boolean
 Dim splitIP() As String, i As Long
 IsIP = True 'Starts out as true
 splitIP$ = Split(strIP$, ".", -1, 1) 'Split IP To check value
 '========================================
 'Things we must check to verify IP
 '1. Make sure there are 4 sections to IP
 '2. Make sure each section of IP is not
 ' greater than 255
 '3. Make sure each section of IP does
 ' not t contain a negative
 '4. Make sure each section of IP is nume-
 ' ric
 '5. Make sure first section of IP is not
 ' 0
 '=======================================
 If UBound(splitIP$) <> 3 Then
  IsIP = False 'make sure there is only 4 nodes =)
 Else
  For i = 0 To UBound(splitIP$) 'loop through array and check 3 things
 
 
   If IsNumeric(splitIP(i)) = False Then
    IsIP = False
    Exit For
   Else
    
    If splitIP(0) = 0 Then 'first digit cannot be 0
     IsIP = False
     Exit For
    End If
 
    If splitIP(i) > 255 Or splitIP(i) < 0 Then
     IsIP = False
     Exit For
    End If
   End If
  Next i
 End If
 
End Function

Download this snippet    Add to My Saved Code

IsIP Function v2 Comments

No comments have been posted about IsIP Function v2. Why not be the first to post a comment about IsIP Function v2.

Post your comment

Subject:
Message:
0/1000 characters