Validate port numbers better
This commit is contained in:
parent
9806d6c12f
commit
2ada552220
4 changed files with 37 additions and 6 deletions
|
@ -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');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue