Skip to content

Commit

Permalink
Update #2 improve-js-regex
Browse files Browse the repository at this point in the history
  • Loading branch information
luukverhoeven committed Jul 22, 2024
1 parent 258a35b commit d0ad8d4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ M.availability_ipaddress.form = Y.Object(M.core_availability.plugin);
*/
M.availability_ipaddress.form.initInner = function() {
"use strict";
Y.log('M.availability_ipaddress 1.2');
Y.log('M.availability_ipaddress 1.2', 'moodle-availability_ipaddress-form');
};

/**
Expand All @@ -92,11 +92,11 @@ M.availability_ipaddress.form.getValue = function(field, node) {
"use strict";
// Get field value.
var value = node.one('input[name=' + field + ']').get('value');
Y.log('ip_address:' + value);
Y.log('ip_address:' + value, 'moodle-availability_ipaddress-form');

// If it is not a valid positive number, return false.
if (M.availability_ipaddress.validateIpaddress(value)) {
Y.log('Valid ip-address');
Y.log('Valid ip-address', 'moodle-availability_ipaddress-form');
return value;
}

Expand Down Expand Up @@ -164,30 +164,30 @@ M.availability_ipaddress.validateIpaddress = function(ipaddresses) {
var ip = ipaddresses[i];

if (new RegExp(M.availability_ipaddress.ipv4Regex).test(ip)) {
Y.log('Correct IPv4: ' + ip);
Y.log('Correct IPv4: ' + ip, 'moodle-availability_ipaddress-form');
continue;
}

if (new RegExp(M.availability_ipaddress.ipv4RangeRegex).test(ip)) {
Y.log('Correct IPv4 range: ' + ip);
Y.log('Correct IPv4 range: ' + ip, 'moodle-availability_ipaddress-form');
continue;
}

if (new RegExp(M.availability_ipaddress.ipv6Regex).test(ip)) {
Y.log('Correct IPv6: ' + ip);
Y.log('Correct IPv6: ' + ip, 'moodle-availability_ipaddress-form');
continue;
}

if (subnetRegex.test(ip)) {
Y.log('Correct subnet: ' + ip);
Y.log('Correct subnet: ' + ip, 'moodle-availability_ipaddress-form');
continue;
}

Y.log('Incorrect IP: ' + ip);
Y.log('Incorrect IP: ' + ip, 'moodle-availability_ipaddress-form');
return false;
}

Y.log('All IP addresses are valid');
Y.log('All IP addresses are valid', 'moodle-availability_ipaddress-form');
return true;
};

Expand Down Expand Up @@ -223,4 +223,4 @@ M.availability_ipaddress.form.fillErrors = function(errors, node) {
};


}, '@VERSION@', {"requires": ["base", "node", "event", "moodle-core_availability-form"]});
}, '@VERSION@', {"requires": ["base", "event", "node", "moodle-core_availability-form"]});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,4 @@ M.availability_ipaddress.form.fillErrors = function(errors, node) {
};


}, '@VERSION@', {"requires": ["base", "node", "event", "moodle-core_availability-form"]});
}, '@VERSION@', {"requires": ["base", "event", "node", "moodle-core_availability-form"]});
18 changes: 9 additions & 9 deletions yui/src/form/js/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ M.availability_ipaddress.form = Y.Object(M.core_availability.plugin);
*/
M.availability_ipaddress.form.initInner = function() {
"use strict";
Y.log('M.availability_ipaddress 1.2');
Y.log('M.availability_ipaddress 1.2', 'moodle-availability_ipaddress-form');
};

/**
Expand All @@ -90,11 +90,11 @@ M.availability_ipaddress.form.getValue = function(field, node) {
"use strict";
// Get field value.
var value = node.one('input[name=' + field + ']').get('value');
Y.log('ip_address:' + value);
Y.log('ip_address:' + value, 'moodle-availability_ipaddress-form');

// If it is not a valid positive number, return false.
if (M.availability_ipaddress.validateIpaddress(value)) {
Y.log('Valid ip-address');
Y.log('Valid ip-address', 'moodle-availability_ipaddress-form');
return value;
}

Expand Down Expand Up @@ -162,30 +162,30 @@ M.availability_ipaddress.validateIpaddress = function(ipaddresses) {
var ip = ipaddresses[i];

if (new RegExp(M.availability_ipaddress.ipv4Regex).test(ip)) {
Y.log('Correct IPv4: ' + ip);
Y.log('Correct IPv4: ' + ip, 'moodle-availability_ipaddress-form');
continue;
}

if (new RegExp(M.availability_ipaddress.ipv4RangeRegex).test(ip)) {
Y.log('Correct IPv4 range: ' + ip);
Y.log('Correct IPv4 range: ' + ip, 'moodle-availability_ipaddress-form');
continue;
}

if (new RegExp(M.availability_ipaddress.ipv6Regex).test(ip)) {
Y.log('Correct IPv6: ' + ip);
Y.log('Correct IPv6: ' + ip, 'moodle-availability_ipaddress-form');
continue;
}

if (subnetRegex.test(ip)) {
Y.log('Correct subnet: ' + ip);
Y.log('Correct subnet: ' + ip, 'moodle-availability_ipaddress-form');
continue;
}

Y.log('Incorrect IP: ' + ip);
Y.log('Incorrect IP: ' + ip, 'moodle-availability_ipaddress-form');
return false;
}

Y.log('All IP addresses are valid');
Y.log('All IP addresses are valid', 'moodle-availability_ipaddress-form');
return true;
};

Expand Down
2 changes: 1 addition & 1 deletion yui/src/form/meta/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"moodle-availability_ipaddress-form": {
"requires": [
"base",
"node",
"event",
"node",
"moodle-core_availability-form"
]
}
Expand Down

0 comments on commit d0ad8d4

Please sign in to comment.