From e5f179330b024671e066edb0672a5a8b628766ed Mon Sep 17 00:00:00 2001 From: zsloan Date: Wed, 26 Jan 2022 20:54:03 +0000 Subject: Replaced the try/catch with something checking for the correct pattern with regex, for validating the Select Rows input --- wqflask/wqflask/static/new/javascript/search_results.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/wqflask/wqflask/static/new/javascript/search_results.js b/wqflask/wqflask/static/new/javascript/search_results.js index b7ad359f..a3e21081 100644 --- a/wqflask/wqflask/static/new/javascript/search_results.js +++ b/wqflask/wqflask/static/new/javascript/search_results.js @@ -102,11 +102,17 @@ $(function() { */ parseIndexString = function(idx_string) { index_list = []; + _ref = idx_string.split(","); for (_i = 0; _i < _ref.length; _i++) { index_set = _ref[_i]; + if (!/^ *([0-9]+$) *| *([0-9]+ *- *[0-9]+$) *|(^$)$/.test(index_set)) { + $('#select_samples_invalid').show(); + break + } else { + $('#select_samples_invalid').hide(); + } if (index_set.indexOf('-') !== -1) { - try { start_index = parseInt(index_set.split("-")[0]); end_index = parseInt(index_set.split("-")[1]); @@ -118,10 +124,6 @@ $(function() { for (index = start_index; index <= end_index; index++) { index_list.push(index); } - } catch (_error) { - error = _error; - alert("Syntax error"); - } } else { index = parseInt(index_set); index_list.push(index); -- cgit 1.4.1