luci-base: add hexstring datatype
authorHannu Nyman <hannu.nyman@iki.fi>
Thu, 9 Feb 2017 14:58:07 +0000 (16:58 +0200)
committerHannu Nyman <hannu.nyman@iki.fi>
Fri, 10 Feb 2017 15:12:57 +0000 (17:12 +0200)
Add datatype 'hexstring' for input validaiton datatypes.

It will accept any hexadecimal string.

(no length validation, as rangelength can be used for that.)

Signed-off-by: Hannu Nyman <hannu.nyman@iki.fi>
(cherry picked from commit 11f23559e4be78f202aa55d811d5b58cb0ca0a78)

modules/luci-base/luasrc/cbi/datatypes.lua

index 72b41ddad89386e4a13c6e715cf747643f67cb60..0a180d366455e1e823c349f537ba21b98d1f789d 100644 (file)
@@ -267,6 +267,13 @@ function wepkey(val)
        end
 end
 
+function hexstring(val)
+        if val then
+                return (val:match("^[a-fA-F0-9]+$") ~= nil)
+        end
+        return false
+end
+
 function string(val)
        return true             -- Everything qualifies as valid string
 end