I have a requirement to not allow illegal characters in a filename, but to allow an apostrophe (single quote), underscore, and comma. My custom pattern is as follows:

-?[ a-zA-Z0-9]*[ a-zA-Z0-9_\-\s\.\\,]+

This works perfectly, but if I try to add a single quote either escaped or not escaped, I receive

an invalid pattern error.

I have Googled until my brain is about to explode. I have seen one other person ask about this and copied the single quote from a word doc then pasted it in, but no response on the outcome.

I tried to follow suit, and although it pasted and did not throw the error, it does not recognize the single quote and will not allow it. Has anyone out there found a solution to this? Most regex languages will allow a single quote without ever escaping it.

Any insight on this would be much appreciated!


I tried below regex and its working as expected

-?[ a-zA-Z0-9]*[ a-zA-Z0-9_\-\s\.\\,']+

Your problem sounds more like an issue with Unicode or UTF characters which has many versions of single quotes - Example ´ will fail the above expression

| improve this answer | |
  • What version did you use? I have tried multiple versions from my Character Map and they do not work. I can copy and paste, but then after publishing the form and testing it, it still throws an validation error as it doesn't recognize it. Maybe I am misunderstanding. Do you mind elaborating a bit. Thanks you in advance. – GoGorilla Oct 23 '17 at 19:30
  • Also, are you testing it in InfoPath with a validation rule? – GoGorilla Oct 23 '17 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.