regex name file

0
I would like to create a validation rule on an system filedocument entity that check the type of the file. For security reason. I only see that the name is available in the entity, so I thought that maybe i could retireve the lasts characters, and check if the value correspond to what I want (for example pdf txt jpeg ...)  The only way to do that seems to put a regular expression. Which I am not an expert. Maybe someone can tell me if this is possible? and maybe help me with the regex, for example :  the last 4 digit equal .txt, or last 5 digit equal .jpeg Thanks!
asked
3 answers
1

Answer on this question is given here: https://forum.mendix.com/link/questions/97776

answered
0

For getting and testing a regex there are great online tools available. For instance www.regex101.com and www.freeformatter.com

This regex will match you the file-extensions:

(.txt|.jpeg)

The AppStore widget ‘File dropper’ has a setting that limits the imported files to only the file-extensions you specify:

answered
0

Hey Yehoshoua,

 

After reviewing my answer given on https://forum.mendix.com/link/questions/97776, I found a more secure RegEx that checks the file format better:

.*(\.txt|\.jpeg|\.png|\.pdf|\.jpg)$

 

My previous regular expression only checked the file format value, and not if it was an actual file format extension. For example, with the old RegEx ‘.*(txt$|jpeg$|png$|pdf$|jpg$)’ both 'filename.txt’ and 'filenametxt’ would match the RegEx. With the new RegEx, only 'filename.txt’ would match.

 

Kind regards,

Cas

answered