我有以下變量賦值驗證用戶輸入的時間在谷歌表
function onEdit(e) {
if (e.range.getColumn() == 3){
var isValid = /^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/.test(e.value);
}
}
我試圖測試是否當一個人編輯在谷歌電子表格的第三列中的值,該值是否他們進入是帶AM或PM的HH:MM格式的有效時間。
我在互聯網上發現了上述情況,但我從未見過這種理解時間的方式。有人可以解釋我發生了什麼,或者將我鏈接到關於上述語法如何工作的文章?
的希望最終能夠做到這樣的事情:
function onEdit(e){
if (the user edits manually edits a value in the third column){
determine whether the value they entered is a valid time
if it is{
let the change go through
}
if it is not{
alert("Sorry your change can't go through");
}
}
}
從我讀的警報已經在正確的語法