[SalesForce] Regular expression to check special symbols not working in lightning javascript

I have a validation function in lightning component that works on regex.
I have a regular expression to check existance of special symbols but I am not able to save my js controller with that regular expression.

Field Integrity Exception:
org.auraframework.util.json.JsonStreamReader$JsonStreamParseException:
Unterminated string [663, 65]: ';'<>?,./]/;': Source

var regularExpression; 
regularExpression = /[-!$%^&*()_+|~=`{}\[\]:";'<>?,.\/]/; //This line is giving error when trying to save 
if(!regularExpression.test(value)) {
     //Action to be taken
}

The code works fine with some other regex's

Best Answer

Try using the constructor syntax.

I've verified that this saves in lightning:

var regularExpression; 
var re = new RegExp('[-!$%^&*()_+|~=`{}\[\]:";\'<>?,.\/]');

Note the escape of the ' char within the expression.

Related Topic