4

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

  • Looks like the compiler doesn't like this. Did you try to use the RegExp constructor? – Martin Lezer Sep 19 '17 at 7:39
4

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.

  • Hi Caspar Harmer, thanks for the reply. But the same expression isn't working if passed to RegExp constructor in single quotes. – Shri Sep 19 '17 at 10:01
0

You need to double the backslash in your expression to make it work.

var regularExpression;

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.