Data Browser - Viewing Site  Sector 23 Code Bank Logged in as:  Guest  




           


Regular Expression Restrict File Types
Here is an example of a regular expression in .NET to restrict user entry to file names with specific extensions (in this case: jpg, jpeg, gif, tif, tiff, pdf, png):

"^.+\.(([jJ][pP][gG])|([jJ][pP][eE][gG])|([gG][iI][fF])|([tT][iI][fF][fF])|([pP][dD][fF])|([tT][iI][fF])|([pP][nN][gG]))$"

Breaking it down:
^ - start
.+ - any text for file name (possible enhancement - restrict to valid file chars)
\. - the last period marking the start of the extension
(([jJ][pP][gG])|([jJ][pP][eE][gG])|([gG][iI][fF])|([tT][iI][fF][fF])|([pP][dD][fF])|([tT][iI][fF])|([pP][nN][gG])) - valid extensions in either upper or lower case
$ - end

Created By: amos 3/18/2013 2:48:52 PM
Updated: 3/18/2013 2:51:05 PM