VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



IsIP Function

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

Checks if string is a valid IP or not. I saw this submitted earlier and made my own better version of it. =)
OK there is now an updated version with fixes so go check it out here:
https://vbcoders.com/vb/scripts/ShowCode.asp?txtCodeId=57999&lngWId=1&txtForceRefresh=123020041845765523

Rate IsIP Function

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 each section of IP is not greater than 255
'2. Make sure each section of IP does not contain a negative
'3. Make sure each section of IP is numeric
'==============================================================
 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(i) > 255 Or splitIP(i) < 0 Then
    IsIP = False
    Exit For
   End If
  End If
 Next i
End Function

Download this snippet    Add to My Saved Code

IsIP Function Comments

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

Post your comment

Subject:
Message:
0/1000 characters