Modul:UrlCheck: Unterschied zwischen den Versionen
K
+ip4
K (path früher abgetrennt) |
K (+ip4) |
||
| Zeile 1: | Zeile 1: | ||
local uc = {} | local uc = {} | ||
function uc.ip4( address ) | |||
local value | |||
local parts = { address:match("(%d+)%.(%d+)%.(%d+)%.(%d+)") } | |||
if #parts == 4 then | |||
for _,value in pairs( parts ) do | |||
if tonumber( value ) < 0 or tonumber( value ) > 255 | |||
then return 0 end | |||
end | |||
return 1 -- ok | |||
else | |||
return 0 | |||
end | |||
end | |||
function uc.isUrl( url ) | function uc.isUrl( url ) | ||
| Zeile 92: | Zeile 106: | ||
-- future: check of top-level domain | -- future: check of top-level domain | ||
if uc.ip4( host ) == 1 then return 0 end -- is ip4 address | |||
if not mw.ustring.match( host, '^[%w%.%-]+%.%a%a+$' ) then return 20 end | if not mw.ustring.match( host, '^[%w%.%-]+%.%a%a+$' ) then return 20 end | ||
if not host:match( '^[%w%.%-]+%.%a%a+$' ) then | if not host:match( '^[%w%.%-]+%.%a%a+$' ) then | ||