From: Metabox Date: Mon, 13 May 2019 07:20:02 +0000 (+1000) Subject: Time check bug fix. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=c357d72f24d2e53c64a91fefb5ff94eb60752bd0;p=LifeLog.git Time check bug fix. --- diff --git a/htdocs/cgi-bin/wsrc/main.js b/htdocs/cgi-bin/wsrc/main.js index 69afee5..a2840bb 100644 --- a/htdocs/cgi-bin/wsrc/main.js +++ b/htdocs/cgi-bin/wsrc/main.js @@ -44,12 +44,46 @@ function formValidation() { } + function validDate(dt) { if (!Date.parse(dt)) { alert("Date -> '" + dt + "' is Invalid can't submit!"); return false; } - return true; + return validTime(dt.substring(dt.indexOf(" ") + 1)); +} + +function validTime(val) { + // regular expression to match required time format + re = /^(\d{2}):(\d{2}):(\d{2})([ap]m)?$/; + var fld = document.getElementById("frm_entry").date; + if (val != '') { + if (regs = val.match(re)) { + // 12-hour value between 1 and 12 + if (regs[1] < 1 || regs[1] > 23) { + alert("Invalid value for hours: " + regs[1]); + fld.focus(); + return false; + } + // minute value between 0 and 59 + if (regs[2] > 59) { + alert("Invalid value for minutes: " + regs[2]); + fld.focus(); + return false; + } + // seconds value between 0 and 59 + if (regs[3] > 59) { + alert("Invalid value for seconds: " + regs[2]); + fld.focus(); + return false; + } + } else { + alert("Invalid time format: " + val); + fld.focus(); + return false; + } + return true; + } } function validLog(log) {