luci-proto-modemmanager: add APN and PIN validation
authorNicholas Smith <nicholas@nbembedded.com>
Fri, 11 Jun 2021 12:19:40 +0000 (22:19 +1000)
committerJo-Philipp Wich <jo@mein.io>
Tue, 15 Feb 2022 23:34:16 +0000 (00:34 +0100)
Signed-off-by: Nicholas Smith <nicholas@nbembedded.com>
[squash commits, fix white space]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit ebb676ef7b03a7fed4062931be147d43d3855b64)

protocols/luci-proto-modemmanager/htdocs/luci-static/resources/protocol/modemmanager.js

index 3825b8ef166ed7c1e2fba86f8738d0e3fb71b1c8..88e516a8ece73244114ef3f8e3e91c45d0682014 100644 (file)
@@ -91,8 +91,16 @@ return network.registerProtocol('modemmanager', {
                        }, this));
                };
 
-               s.taboption('general', form.Value, 'apn', _('APN'));
-               s.taboption('general', form.Value, 'pincode', _('PIN'));
+               o = s.taboption('general', form.Value, 'apn', _('APN'));
+               o.validate = function(section_id, value) {
+                       if (!/^[a-zA-Z0-9\-.]*[a-zA-Z0-9]$/.test(value))
+                               return _('Invalid APN provided');
+
+                       return true;
+               };
+
+               o = s.taboption('general', form.Value, 'pincode', _('PIN'));
+               o.datatype = 'and(uinteger,minlength(4),maxlength(8))';
 
                o = s.taboption('general', form.ListValue, 'auth', _('Authentication Type'));
                o.value('both', _('PAP/CHAP (both)'));