web: Improve hostname validation
[project/luci.git] / libs / web / luasrc / cbi / datatypes.lua
index 67cb63daf048ec8d4511f27560fb7c8103a280b6..d1ac8f405a93c494359dd74eb3eefb531ed03898 100644 (file)
@@ -127,10 +127,9 @@ function macaddr(val)
 end
 
 function hostname(val)
-       if val and val:match("[a-zA-Z0-9_][a-zA-Z0-9_%-%.]*") then
-               return true     -- XXX: ToDo: need better solution
+       if val and (#val < 25) and val.match(val, "^[a-zA-Z0-9][a-zA-Z0-9%-%.]*[a-zA-Z0-9]$") then
+               return true
        end
-
        return false
 end