libs/web: improve ip6addr datype validation, accept both CIDR and IP/Mask notation
authorJo-Philipp Wich <jow@openwrt.org>
Tue, 20 Dec 2011 02:44:32 +0000 (02:44 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Tue, 20 Dec 2011 02:44:32 +0000 (02:44 +0000)
libs/web/htdocs/luci-static/resources/cbi.js

index 4b8cd5c..3826753 100644 (file)
@@ -49,13 +49,15 @@ var cbi_validators = {
 
        'ip4addr': function(v)
        {
 
        'ip4addr': function(v)
        {
-               if( v.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)(\/(\d+))?$/) )
+               if (v.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})(\/(\S+))?$/))
                {
                        return (RegExp.$1 >= 0) && (RegExp.$1 <= 255) &&
                               (RegExp.$2 >= 0) && (RegExp.$2 <= 255) &&
                               (RegExp.$3 >= 0) && (RegExp.$3 <= 255) &&
                               (RegExp.$4 >= 0) && (RegExp.$4 <= 255) &&
                {
                        return (RegExp.$1 >= 0) && (RegExp.$1 <= 255) &&
                               (RegExp.$2 >= 0) && (RegExp.$2 <= 255) &&
                               (RegExp.$3 >= 0) && (RegExp.$3 <= 255) &&
                               (RegExp.$4 >= 0) && (RegExp.$4 <= 255) &&
-                              (!RegExp.$5 || ((RegExp.$6 >= 0) && (RegExp.$6 <= 32)))
+                                  ((RegExp.$6.indexOf('.') < 0)
+                                               ? ((RegExp.$6 >= 0) && (RegExp.$6 <= 32))
+                                               : (cbi_validators.ip4addr(RegExp.$6)))
                        ;
                }
 
                        ;
                }