Skip to content

Instantly share code, notes, and snippets.

@stefango
Last active December 2, 2020 08:54
Show Gist options
  • Save stefango/c3734c481a9e0997b16e5a5c4606258f to your computer and use it in GitHub Desktop.
Save stefango/c3734c481a9e0997b16e5a5c4606258f to your computer and use it in GitHub Desktop.
let value = "2020-12-01 17:00"
//let value = "17:00"
//let value = "00:00"
let timeReg = /^(0?[0-9]|1[0-9]|2[0-3]):(0?[0-9]|[1-5][0-9])$/gi;
let dateReg = /^[1-2]\d{3}\-(0[1-9]|1[0-2])\-(0[1-9]|[1-2][0-9]|3[0-1])$/gi;
let isDateTime = false;
let arr = value.split(" ");
if (arr.length==2 && dateReg.test(arr[0]) && timeReg.test(arr[1])) {
isDateTime = true;
}
if (!(timeReg.test(value) || isDateTime)) {
value=encodeURIComponent(value);
}
console.log(value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment