IP Address Validation?

  • Thread starter Thread starter GD
  • Start date Start date
How do you setup a column to accept an IP address format only, i.e.,
999.999.999.999?

Do you want IP address format only or do you want valid IP address format?

Valid IP addresses would have each octet in the range of 0-255.

So you would use Data/Validation Custom with the formula:

=AND(--LEFT(I1,FIND(".",I1)-1)<256,
--(MID(SUBSTITUTE(I1,".",REPT(" ",99)),99,99))<256,
--(MID(SUBSTITUTE(I1,".",REPT(" ",99)),198,99))<256,
--TRIM(RIGHT(SUBSTITUTE(I1,".",REPT(" ",99)),99))<256)

where I1 is the cell you are formatting.

Then execute copy/paste special/validation to copy the validation to the rest
of the column.

The above is not foolproof as it allows for "negative" octets. But a formula
using this approach won't work in the Data Validation box since there seems to
be a limit of 255 characters in the data validation formula box, and adding in
checks for the octets to also be >=0 would make this formula too long.

One way around that would be to put the full formula in a hidden "helper"
column, and use the data validation to check for TRUE or FALSE in that column.
--ron
 
You could put something in a worksheet change instead of data validation. Of
course, that would assume that macros are enabled.

Barb Reinhardt
 
Hi,

1. An alternate but not quite as complex a solution would be to choose
Data, Validation, Whole Numbers, Between 100000000000 and 999999999999.
And then to apply a custom format to the cell of 000"."000"."000"."000 by
going to Format, Cell, Number tab, Custom. Or if a valid address could be
000.000.000.001 then set the lower limit to 1.

2. If you want a stronger data validation then:
Use the custom with a formula of the following typ
=AND(LEN(F1)=12,--LEFT(F1,3)<256,--MID(F1,4,3)<256,--MID(F1,7,3)<256,--MID(F1,10,3)<256)
Where you are applying it to the cell F1 to start. Now have the user enter
the IP address without decimal points and use the format I showed in #1.


If this is helpful, click the Yes button.
 
Hi,


2. If you want a stronger data validation then:
Use the custom with a formula of the following type
=AND(LEN(F1)=12,--LEFT(F1,3)<256,--MID(F1,4,3)<256,--MID(F1,7,3)<256,--MID(F1,10,3)<256)
Where you are applying it to the cell F1 to start. Now have the user enter
the IP address without decimal points and use the format I showed in #1.

This disallows many acceptable IP addresses. Among others, it will exclude any
IP addresses where the first octet is less than 100. It also requires that
each octet be entered as three digits, which is not required for a valid IP
address.
--ron
 
This is exactly what i need. Thank you.

Ron Rosenfeld said:
Do you want IP address format only or do you want valid IP address format?

Valid IP addresses would have each octet in the range of 0-255.

So you would use Data/Validation Custom with the formula:

=AND(--LEFT(I1,FIND(".",I1)-1)<256,
--(MID(SUBSTITUTE(I1,".",REPT(" ",99)),99,99))<256,
--(MID(SUBSTITUTE(I1,".",REPT(" ",99)),198,99))<256,
--TRIM(RIGHT(SUBSTITUTE(I1,".",REPT(" ",99)),99))<256)

where I1 is the cell you are formatting.

Then execute copy/paste special/validation to copy the validation to the rest
of the column.

The above is not foolproof as it allows for "negative" octets. But a formula
using this approach won't work in the Data Validation box since there seems to
be a limit of 255 characters in the data validation formula box, and adding in
checks for the octets to also be >=0 would make this formula too long.

One way around that would be to put the full formula in a hidden "helper"
column, and use the data validation to check for TRUE or FALSE in that column.
--ron
 
Back
Top