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:
^[^.]+$
matches string no dots\.(?!(js|exe)$)([^.]+$)
matches dot if not followedjs
orexe
@ 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
Post a Comment