View source for Module:IPAddress
Jump to navigation
Jump to search
You do not have permission to edit this page, for the following reason:
You can view and copy the source of this page.
local p = {}
function p._isIpV6(s)
local dcolon, groups
if type(s) ~= "string"
or s:len() == 0
or s:find("[^:%x]") -- only colon and hex digits are legal chars
or s:find("^:[^:]") -- can begin or end with :: but not with single :
or s:find("[^:]:$")
or s:find(":::")
then
return false
end
s, dcolon = s:gsub("::", ":")
if dcolon > 1 then return false end -- at most one ::
s = s:gsub("^:?", ":") -- prepend : if needed, upper
s, groups = s:gsub(":%x%x?%x?%x?", "") -- remove valid groups, and count them
return ( (dcolon == 1 and groups < 8) or (dcolon == 0 and groups == 8) )
and ( s:len() == 0 or (dcolon == 1 and s == ":") ) -- might be one dangling : if original ended with ::
end
000
1:0
Templates used on this page:
- Template:Sandbox other (view source)
- Template:Used in system (view source)
- Module:Effective protection level (view source)
- Module:High-use (view source)
- Module:IPAddress/doc (view source)
- Module:Message box (view source)
- Module:Message box/configuration (view source)
- Module:No globals (view source)
- Module:String (view source)
- Module:Transclusion count (view source)
- Module:Transclusion count/data/I (view source)
- Module:Yesno (view source)
Return to Module:IPAddress.