I have a .NET webform that has a file upload control that is tied to a regular expression validator. This validator needs to validate that only certain filetypes should be allowed for upload (jpg,gif,doc,pdf)
The current regular expression that does this is:
^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.jpg|.JPG|.gif|.GIF|.doc|.DOC|.pdf|.PDF)$
However this does not seem to be working… can anyone give me a little reg ex help?
Your regex seems a bit too complex in my opinion. Also, remember that the dot is a special character meaning ‘any character’. The following regex should work (note the escaped dots):
You can use a tool like Expresso to test your regular expressions.