IP Addresses validation

A

Allen Browne

Use four Number fields of size Byte.

Easy enough to concatenate them with dots for display purposes.
 
J

John Crighton

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
 
A

Allen Browne

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.
 
R

Reed

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top