IPv4 Data validity possible?

Discuss the spreadsheet application
Post Reply
bmmcwhirt
Posts: 15
Joined: Fri Jun 28, 2013 3:56 pm

IPv4 Data validity possible?

Post by bmmcwhirt »

Is it possible, and if so how, to set up data validity for IPv4 addresses to force them to be entered as follows: ###.###.###.### (always 3 digits for each octet)

192.168.000.001 VALID
192.168.00.01 INVALID
192.168.0.1 INVALID
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: IPv4 Data validity possible?

Post by Villeroy »

=ISNUMBER(SEARCH("^[0-9]{3}\.[0-9]{3}\.[0-9]{3}\.[0-9]{3}$";A1))
but that does not prevent invalid IPs such as 999.999.999.999
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
bmmcwhirt
Posts: 15
Joined: Fri Jun 28, 2013 3:56 pm

Re: IPv4 Data validity possible?

Post by bmmcwhirt »

Villeroy wrote:=ISNUMBER(SEARCH("^[0-9]{3}\.[0-9]{3}\.[0-9]{3}\.[0-9]{3}$";A1))
but that does not prevent invalid IPs such as 999.999.999.999

In the criteria tab, what settings do I need for allow?
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: IPv4 Data validity possible?

Post by Villeroy »

If you know the allowed IP range, you can try this:
Allow integer values between 0 and 255 for 4 cells in a row and then concatenate the IP like this:
=CONCATENATE(TEXT(A1;"000");".";TEXT(B1;"000");".";TEXT(C1;"000");".";TEXT(D1;"000"))
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
bmmcwhirt
Posts: 15
Joined: Fri Jun 28, 2013 3:56 pm

Re: IPv4 Data validity possible?

Post by bmmcwhirt »

Villeroy wrote:If you know the allowed IP range, you can try this:
Allow integer values between 0 and 255 for 4 cells in a row and then concatenate the IP like this:
=CONCATENATE(TEXT(A1;"000");".";TEXT(B1;"000");".";TEXT(C1;"000");".";TEXT(D1;"000"))
No, this is all going into one cell. When I edit the Data Validity though I only have Allow: All values, whole numbers, decimal, date, time, cell range, list, text length.

There is not custom or anything that I can see to allow me to do this, but it seems like there should be a way.
User avatar
RusselB
Moderator
Posts: 6646
Joined: Fri Jan 03, 2014 7:31 am
Location: Sarnia, ON

Re: IPv4 Data validity possible?

Post by RusselB »

Villeroy's suggestions do not require you to use Data Validation.
If you know the IP range (and don't mind doing what could be a lot of typing), then you could put the list of valid IP addresses into a list or cell range.
If the 2nd of Villeroy's formulas looks interesting, except for the fact that it uses multiple cell addresses, you could split the IP address into 4 sections using combinations of SEARCH, LEFT, MID and/or RIGHT functions into helper cells.
If you don't want to use helper cells, then you could replace the calculated sections (using the same methods as for getting helper cells) directly into Villeroy's formula.
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: IPv4 Data validity possible?

Post by John_Ha »

Presumably it could be done with a Regular Expression - Documentation/How Tos/Regular Expressions in Calc.

Ms Google quickly found thousands of sites like Validating IPv4 addresses with regexp
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
bmmcwhirt
Posts: 15
Joined: Fri Jun 28, 2013 3:56 pm

Re: IPv4 Data validity possible?

Post by bmmcwhirt »

It has to be done in Data Validity as I need to have an alert pop up when someone enters an invalid format.
User avatar
RusselB
Moderator
Posts: 6646
Joined: Fri Jan 03, 2014 7:31 am
Location: Sarnia, ON

Re: IPv4 Data validity possible?

Post by RusselB »

I think, in that case, your only option is to make a list either in the Data Validity dialog or in a cell range and pick the appropriate Data Validity option.
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: IPv4 Data validity possible?

Post by Villeroy »

Conditional formatting as "alert pop up"
Attachments
IPv4_regex.ods
(13.68 KiB) Downloaded 51 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
bmmcwhirt
Posts: 15
Joined: Fri Jun 28, 2013 3:56 pm

Re: IPv4 Data validity possible?

Post by bmmcwhirt »

That's good but isn't usable for me as it doesn't actually stop them from entering wrong data. At best it can delete the data after they enter it but thanks to the US education system they will just go on as if it was entered correctly. I would use macro scripting but we have all that disabled for security reasons.
User avatar
RusselB
Moderator
Posts: 6646
Joined: Fri Jan 03, 2014 7:31 am
Location: Sarnia, ON

Re: IPv4 Data validity possible?

Post by RusselB »

bmmcwhirt wrote:That's good but isn't usable for me as it doesn't actually stop them from entering wrong data. At best it can delete the data after they enter it but thanks to the US education system they will just go on as if it was entered correctly. I would use macro scripting but we have all that disabled for security reasons.
US Education System should (and probably does) have employees in the IT department to handle these kinds of restrictions.
For something that will prevent the immediate entry of an invalid IP address, that is the department that should be handling this, not a user working with a spreadsheet.
OpenOffice 4.1.7, LibreOffice 7.0.1.2 on Windows 7 Pro, Ultimate & Windows 10 Home (2004)
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: IPv4 Data validity possible?

Post by Villeroy »

If anyone is interested and authorized to use macros:
Call menu:Tools>Options>Security>[Macro Security]
Do NOT turn off macro security but add a trusted directory.
Save the attached database document to the trusted directory.
Open the document and then any of the 2 input forms.
Attachments
IPv4_entry.odb
(22.08 KiB) Downloaded 56 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: IPv4 Data validity possible?

Post by Villeroy »

And another one for those who are interested in solutions with no macros.
Attachments
IPv4_Bytes.odb
(11.74 KiB) Downloaded 52 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: IPv4 Data validity possible?

Post by Villeroy »

If you need a list of unique IP strings in a spreadsheet, save a query within the 2nd database

Code: Select all

SELECT DISTINCT "IP" FROM "qConcat_IPv4" 
Register the database under some name in Tools>Options>Base>Databases
Open a Calc document
Get the data source window (F4 should do)
Browse your registered database --> Queries and drag your query into the sheet.

After the database has been changed, menu:Data>Refresh (cell cursor in range) will update the import range.

A query to get the IPs where the first byte equals 182

Code: Select all

SELECT "IP" FROM "qConcat_IPv4" WHERE "B1"=182
A query which prompts you to enter the first characters of an IP string:

Code: Select all

SELECT "IP" FROM "qConcat_IPv4" WHERE "IP" LIKE :IP_starts_with || '%'

The last 5 entries

Code: Select all

SELECT "IP" FROM "qConcat_IPv4" ORDER BY "ID" DESC LIMIT 5
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply