diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2015-03-20 05:56:07 +0000 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2015-03-20 05:56:07 +0000 |
commit | a2f5ef9645401a7460b46092a1eeeecd6774d69a (patch) | |
tree | 96469169229bdf972f3995d01f73ea8ce6b1ab49 | |
parent | 9694f172f649ce3e2b47397460a2624a68882e22 (diff) | |
download | sariulclocks-a2f5ef9645401a7460b46092a1eeeecd6774d69a.tar.gz |
validate custom countdown input
-rw-r--r-- | assets/js/main.js | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/assets/js/main.js b/assets/js/main.js index d10911b..f1e9dc4 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -1,3 +1,7 @@ +// compile regular expressions + +var numRegExp = new RegExp("^[0-9]*$"); + // sound setup $.ionSound({ @@ -120,8 +124,8 @@ function endLesson() return false; // validate - var valRegExp = new RegExp("^[0-9]*$"); - if (valRegExp.test($points.val()) == false) + var numRegExp = new RegExp("^[0-9]*$"); + if (numRegExp.test($points.val()) == false) { alert ("invalid points!"); return false; @@ -224,9 +228,14 @@ function MyFlipClock (jq, obj) thisClock.setTime(0); }, thisClock); thisClock.custom = $.proxy(function () { - var minutes = parseInt(prompt('Number of minutes', '0')); - var seconds = parseInt(prompt('Number of seconds', '0')); - thisClock.go(minutes * 60 + seconds); + var minutes = prompt('Number of minutes', '0'); + var seconds = prompt('Number of seconds', '0'); + + // validate + if (numRegExp.test(minutes) == false || numRegExp.test(seconds) == false) + alert ("invalid input"); + else + thisClock.go(parseInt(minutes) * 60 + parseInt(seconds)); }, thisClock); return thisClock; |