Suppose I have a data object with regex in it, that is being fetched from an api, in the form-
data = {regex : "/^[\p{L} .’_-]+$/u"}
If I assign data-parsley-pattern = data.regex, parsley.js transforms it into a format that always results to false where converted= /^\/^[\p{L} .’-]+$\/u$/
If I directly assign data.regex= /^[\p{L} .’-]+$/u then it works fine.
I have tried to converted the stringified regex to object before assigning it, but nothing seems to work. the regex is always changed into something that gives the validation result as false even if value is correct.
The code I used to convert stringified regex to regex object is given here-
const data = { regex : "/^[\p{L} .’_-]+$/u" };
const [, regex, flags] = data.regex.match(/^\/(.)\/([a-z])$/);
const pattern = new RegExp(regex, flags);
console.log(pattern.test('check')); //this results to true
What kind of issue is this? (put 'x' between the square brackets)
[ ] Question. This issue tracker is not the place for questions. If you want to ask how to do something, or to understand why something isn't working the way you expect it to, use http://stackoverflow.com/questions/ask . Provide working code, starting from http://codepen.io/marcandre/pen/jqbzyN?editors=101. We monitor the tag
parsley.js
.[ ] Bug report. If you’ve found a bug, you must provide a minimal example in a CodePen, starting from http://codepen.io/marcandre/pen/jqbzyN?editors=101 .
[x] Feature Request. Make sure there's no good way to do what you want first; consider asking on http://stackoverflow.com/questions/ask first.
Suppose I have a data object with regex in it, that is being fetched from an api, in the form- data = {regex : "/^[\p{L} .’_-]+$/u"}
If I assign data-parsley-pattern = data.regex, parsley.js transforms it into a format that always results to false where converted= /^\/^[\p{L} .’-]+$\/u$/ If I directly assign data.regex= /^[\p{L} .’-]+$/u then it works fine. I have tried to converted the stringified regex to object before assigning it, but nothing seems to work. the regex is always changed into something that gives the validation result as false even if value is correct.
The code I used to convert stringified regex to regex object is given here-
const data = { regex : "/^[\p{L} .’_-]+$/u" }; const [, regex, flags] = data.regex.match(/^\/(.)\/([a-z])$/); const pattern = new RegExp(regex, flags); console.log(pattern.test('check')); //this results to true