I want to test a regular expresion like this: 213+123, a number plus + plus a number. This is de code:
var re = /\d+[+]\d+/
result = window.eval(command);
var bool = re.test(result);
The code respond false if I try to enter 234+234. Any help
The problem is not the regex but the eval.
var command = "234+234";
var result = window.eval(command); // result will be 468 so the regex will fail
var bool = re.test(result); // equals re.test(468);
Instead call it on the command
var command = "234+234";
var bool = re.test(command); // equals re.test("234+234");
re.test(command)? If you eval213+123, you get back the result of the expression, which is a single number.evalis not safe with user input. I have written asumupfunction that does the parsing in a safer manner.evaling the user's own input is not unsafe... after all, they could also just type the code in the console.