IP address data entry / validation ideas?

An application I'm working on has a table of assets and one column is the IP address. Has anyone figured out a neat solution for data entry and validation? Presumably I'd have to render the column as a view.

I've played around with 255.255.255.255 using four numeric entry fields with lower and upper limits of 0 and 255. But this accepts decimals (7.3, etc.). Out-of range values can be handled by the invalidStyle settings to give a red border, or whatever. It does support the Tab key to move between fields, which is a help.

Any tips?

Formatted text fields using appropriate regex? Not vision, whoops.

1 Like

How much do you hate your users?

Four 255 entry dropdowns?
+/- buttons?
Entry only as hexadecimal?

This reminds me of the 'worst way to enter a phone number' challenge that was on reddit or similar.

3 Likes

Extra marks if the dropdowns are not in numeric order.

4 Likes

Put them in alphabetical order

5 Likes

On a more serious note, text field, deferUpdates and rejectUpdatesWhileFocused off. Value change event that fires on browser source only, that applies regex filter to entered value and strips unallowed items (\D if using java regex) or enters the max/min value if going beyond edges and writes it back to a custom property on the view. The numeric entry is bound unidirectionally to this custom property.

I think you could also use this script to send focus to the next box on 3rd digit entry.

Might still be racey or loop inducing.

3 Likes

put them in order of 'number of pixels in number when written in arial'

almost but not quite numerical order

1 Like

If you're looking for a regex pattern:

import re

def isIPv4(IPString):
	pattern = "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
	return len(re.findall(pattern, IPString)) > 0


ipList = ['192.168.1.1',
          '8.8.8.8',
          '10.70.256.3',
          '12.5.68.3.88'
         ]
         
for ip in ipList:
	print '{:19}'.format(ip), isIPv4(ip)

Output:

192.168.1.1         True
8.8.8.8             True
10.70.256.3         False
12.5.68.3.88        False
>>> 
3 Likes

That's a neat trick.

Java example:

from java.util.regex import Pattern
ipv4 = Pattern.compile( 
	"^(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"
)

def isIPv4(ip_string):
	return ipv4.matcher(ip_string).matches()


ipList = [
	'192.168.1.1',
	'8.8.8.8',
	'10.70.256.3',
	'12.5.68.3.88'
]

for ip in ipList:
	print '{:19}'.format(ip), isIPv4(ip)
192.168.1.1         True
8.8.8.8             True
10.70.256.3         False
12.5.68.3.88        False
3 Likes