IP Addresses validation

  • Thread starter Thread starter Tony
  • Start date Start date
Use four Number fields of size Byte.

Easy enough to concatenate them with dots for display purposes.
 
Hi Tony,

If the bytes are in different fields (i.e. 1,2,3 and 4)
then this would be fairly easy, (i.e. <=255 AND >=0)
however I expect that you're talking about one string...?

If so, you could use the Mid function to extract each
number from the string and find out if it's numeric, e.g.:

Dim strMyIP As String
Dim strInput As String
Dim intCount As Integer

strInput = Me.IP_Address
intCount = 0

Do Until intCount = 4
Do Until Mid(strInput,1,1) = "."
If IsNumeric(Mid(strInput,1,1)) Then
strMyIP = strMyIP & Mid(strInput,1)
'chop off the end digit...
strInput = Mid(strInput,2)
Else
MsgBox "Invalid IP Address"
Exit Sub
End If
Loop
If strMyIP >255 Or strMyIP <0 Then
MsgBox "Invalid IP Address"
Exit Sub
Else
strMyIP = ""
intCount = intCount + 1
End If
Loop
MsgBox "Valid IP Address"


Although I've not tested that, something along those
lines should work.

HTH

John C
 
Antonio, can you change it to 4 Number fields instead?
Use a seperate field for the CIDR.

The Byte field accepts numbers between 0 and 255 only.
There is just no way to enter a value outside that range.
 
Allen,
This seems to be a common posting. I have an example, but
no web site to put it on. I think that his could be a good
think for those that need help in this area. Do you want
to post my sample on your sight?

Email me if you do.

Reed
 
Back
Top