luci-base: validation.js: implement length() datatype validator
authorJo-Philipp Wich <jo@mein.io>
Wed, 11 Sep 2019 10:28:58 +0000 (12:28 +0200)
committerJo-Philipp Wich <jo@mein.io>
Wed, 11 Sep 2019 10:28:58 +0000 (12:28 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/validation.js

index ca544cb15d0d71af5aa233560bf60d6821eefb76..79ae1d67070efa8a0e078099c4c36e19fad37b15 100644 (file)
@@ -419,6 +419,12 @@ var ValidatorFactory = L.Class.extend({
                        return this.assert(this.factory.parseDecimal(this.value) <= +max, _('value smaller or equal to %f').format(max));
                },
 
+               length: function(len) {
+                       var val = '' + this.value;
+                       return this.assert(val.length == +len,
+                               _('value with %d characters').format(len));
+               },
+
                rangelength: function(min, max) {
                        var val = '' + this.value;
                        return this.assert((val.length >= +min) && (val.length <= +max),