Case insensitive regular expression validation of text field

Hi all,
I want to validate a text field in a form with case insensitive regular expression pattern, but I dont know how to set the modifier.

Let’s say the text is a filename that has to end with “.pdf”.
The pattern could be “.*\.pdf”, but ending with “.PDF” will also be ok.
So I want to use the case insensitive modifier i, but that does not work “/.*\.pdf/i”.

Any ideas how to set the modifiers for regular expression?

Please suggest nothing like “.*\.pdf|.*\.PDF”, in real the pattern is more complicated.
Thanks for your help.
Ingo

.Net:

RegEx.IsMatch("Hello", "HELLO", RegexOptions.IgnoreCase)

taken from:

Javascript:
we do have also the regex options like i - for ignoring Case
e.g.

const str = 'abc.pdf';
const globalRegex = new RegExp('.*\.PDF', 'i');
console.log(globalRegex.test(str));
// expected output: true

Another strategy could to set the text for the compare to lower / upper case

1 Like

Thanks Peter!

I think I need to make this more specific.
I’m talking about the validation in a Form Activity, where I dont know how to set the regex modifier.

As you had already tried the /i option, we would look for alternates.
In such a case we would check if a custom validation via an expression can handle it.

Unfortunately the Javascript flavor of regex does not support inline modifiers. In other flavors of regex you can use (?i) to ignore case.

A workaround is to edit the json string and add a custom validation:

{
  "label": "Test",
  "tableView": true,
  "validate": {
    "custom": "valid = (/^.*\\.pdf$/i.exec(input) === null) ? 'Wrong format!' : true;"
  },
  "key": "test",
  "type": "textfield",
  "input": true
}

Thank you very much for your effort, ptrobot, that’s the solution.
Ingo

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.