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.
RegEx.IsMatch("Hello", "HELLO", RegexOptions.IgnoreCase)
This CheatSheet introduces the basic use of regex functions. With further examples also special cases are presented.
From the namespace System.Text.RegularExpressions following methods are offered:
A simple usage for example would look like this:
add System.Text.RegularExpressions to the imports:
it allows to use the shortened statement, as the namespace part can be ommited…
we do have also the regex options like i - for ignoring Case
const str = 'abc.pdf';
const globalRegex = new RegExp('.*\.PDF', 'i');
// expected output: true
Another strategy could to set the text for the compare to lower / upper case
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.
A workaround is to edit the json string and add a custom validation:
"custom": "valid = (/^.*\\.pdf$/i.exec(input) === null) ? 'Wrong format!' : true;"
Thank you very much for your effort, ptrobot, that’s the solution.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.