var regExpression = /^([a-zA-Z0-9_\-\.]+)$/; //line 2
//// var regExpression = "/" + "^([a-zA-Z0-9_\-\.]+)$" + "/"; //line 3
alert (regExpression.test("11aa"));
The above code is working fine.
But if we replace line 2 with line 3, then it does not work.
Why? I am in a situation like I want to create var only by adding (the expression comes dynamically), so what should I do?
source
share