Module talk:IPAddress
Latest comment: 12 years ago by DixonD in topic More than 3 digits in a group
isIp
Takes a single argument, a string, and returns:
- "6" if it is a valid IPV6 address
- "4" if it is a valid IPV6 address
- empty string if it is neither.
When applied to {{PAGENAME}}, this helps determine whether a template is being placed on an anonymous user page/user talk page or not, as used in Template:AfC talk:
{{#if:{{IsIPAddress|{{PAGENAME}}}}|I'm on an anonymous IP user or user talk page|I'm on some other page}}
Note that extra whitespace is not permitted (e.g. "127.0.0.1 " with an extra space at the end is not a valid IP address).
isIpV6
Returns 1 if the given argument is a valid IPv6 address, else 0.
isIpV4
Returns 1 if the given argument is a valid IPv4 address, else 0.
More than 3 digits in a group
Is '00000000000005.10.10.10' a correct IPv4 address? --DixonD (talk) 07:53, 8 March 2013 (UTC)
- good question. it's not so much about "more than 3 digits" as it's about leading zeroes: is 12.02.4.4 legal? how about 12.00.4.4? what are the rules?
- current code allows those, as well as 1.00000000100.2.2, i.e, any number can be preceded by any number of 0's. it's relatively easy to disallow. from Dot-decimal notation#Caveat it can be concluded that preceding with 0's is not a good idea, and can lead to confusion- this may be interpreted sometimes to mean "octal". should i change the code to disallow? should we add it to the tests? peace - קיפודנחש (aka kipod) (talk) 09:06, 8 March 2013 (UTC)
- Yes, I think it is better to disallow. I would change the regexp from "^(%d+)%.(%d+)%.(%d+)%.(%d+)$" to something like "^(%d{1,3})%.(%d{1,3})%.(%d{1,3})%.(%d{1,3})$". --DixonD (talk) 12:11, 8 March 2013 (UTC)