Validate port numbers better

This commit is contained in:
Ken-Håvard Lieng 2018-05-18 03:39:40 +02:00
parent 9806d6c12f
commit 2ada552220
4 changed files with 37 additions and 6 deletions

View file

@ -122,6 +122,21 @@ export function isValidUsername(username) {
return true;
}
export function isInt(str, min, max) {
if (!str || str < min || str > max) {
return false;
}
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i);
if (char < 48 || char > 57) {
return false;
}
}
return true;
}
export function timestamp(date = new Date()) {
const h = padStart(date.getHours(), 2, '0');
const m = padStart(date.getMinutes(), 2, '0');