diff --git a/api/controller.js b/api/controller.js index 949731c..f3a8f20 100644 --- a/api/controller.js +++ b/api/controller.js @@ -42,3 +42,10 @@ exports.calculate = function(req, res) { res.json({ result: operation(req.query.operand1, req.query.operand2) }); }; + +//Make a change + if (!req.query.operand2 || + !req.query.operand2.match(/^(-)?[0-9\.]+(e(-)?[0-9]+)?$/) || + req.query.operand2.replace(/[-0-9e]/g, '').length > 1) { + throw new Error("Invalid operand2: " + req.query.operand2); + }