Validate IP Address
On Fri, 11 Sep 2009 17:14:02 -0700, HarryisTrying
wrote:
This works but it doesn't reject input with more than 4 octets
xxx.xxx.xxx.xxx.yyy
Thanks and I will use this to try and learn some more
--
Thank You
Here's another approach that will reject
1.1.1.1.1
but accept
1.1.1.1.1 1.1.1.1
since the latter "contains" a valid IP address that is separated from the
invalid construct:
===============================
Option Explicit
Function containsIP(str As String) As Boolean
Dim re As Object
Set re = CreateObject("vbscript.regexp")
re.Pattern = _
"(?:^|\s)\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b(?:\s|$)"
containsIP = re.Test(str)
Set re = Nothing
End Function
===========================
--ron
|