javascript - Regular expression for excluding file types .exe and .js -


i using jquery file upload plugin, giving value option accept files need regular expression tells file types restricted. need restrict both exe , js achieved using below expression

(\.|\/)(!exe|!js)$

but expression not allowing other files tried adding 1 extension below

(\.|\/)(!exe|!js|pdf)$

with above regular expression accepting pdf , not accepting exe , js. need enable file extentions except exe , js. difficult add extensions expression. can mention how in expression accept other filetypes except exe , js in similar format above. regular expression js.

thanks,

vinay

this exclude .js , .exe @ end of string, allow else:

/^[^.]+$|\.(?!(js|exe)$)([^.]+$)/ 

broken down:

  1. ^[^.]+$ matches string no dots
  2. \.(?!(js|exe)$)([^.]+$) matches dot if not followed js or exe @ end of string.

the following allowed:

  • something.js.notjs
  • somethingelse.exee
  • /something.js/foo

the following not allowed:

  • jquery.js
  • outlook.exe

note: excluding file extensions not substitute security, , if js , exe files not comprehensive blacklist. if purpose in excluding extensions protect server or users, consider white list of extensions , thorough validation of file data after upload.


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -