Dynamic regex in text area Form

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? :smiley:

Till now, my solution:

  1. So, I get a list of forbidden words to type in, let’s say I have [“One”,“Two”,“Three”]

  2. I build the regex “/^(?!One$|Two$|Three$).*$/gmi”, which excludes these names

  3. 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

I write a listed item

I write a non listed item

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

@jmedinacarbonell so you want to put values dynamic in regex string and then you want to use it in whole code. Am i right?

Hi @raja.arslankhan thanks for your help,
I want to pass a variable inside the JSON config from the text area component.
In this case yes, it’s a regex

@loginerror do you thing I should move this to feature request section?
Thanks in advance