Hi family,
I want a form which tells me, when writting a name, if it’s invalid or not. This chriteria comes from a dynamic list I pass to the Text Area Component as a regex pattern… Interesting right?
Till now, my solution:
-
So, I get a list of forbidden words to type in, let’s say I have [“One”,“Two”,“Three”]
-
I build the regex “/^(?!One$|Two$|Three$).*$/gmi”, which excludes these names
-
Then, I want to add this regex to its form pattern’s field… it results (hardcoded) something like this in JSON schema:
{
"label": "Text Area",
"tableView": true,
"validate": {
"custom": "valid = (/^(?!One$|Two$|Three$).*$/gmi.exec(input) === null) ? 'Wrong format!' : true;"
},
"key": "textArea",
"type": "textarea",
"input": true,
"keyModified": true
}
It works FINE when hardcoding BUT… How can I do it from a dynamic value?
-
Let’s say, I create a variable called
regexTest="/^(?!One$|Two$|Three$).*$/gmi"
-
I pass it inside the form designer as a “FormFieldsCollection” variable
-
Then I try something like:
{
(...)
"custom": "valid = ({{data.regexTest}}.exec(input) === null) ? 'Wrong format!' : true;"
(...)
I’ve already tried many options like this but I can’t go forward…
Any idea?
Thanks in advance, hug!
From Case insensitive regular expression validation of text field - #5 by ptrobot