Regular Expressions

  • Thread starter Thread starter Singularity.co.uk
  • Start date Start date
S

Singularity.co.uk

Hi

Does anyone have or know of a regular expression for preventing users from
browsing to and selecting an .exe or .vbs file in a file type form object?

If not, are there any good tutorials or articles that may be of benefit?

I don't want users to be able to upload these types of files to my site.

Thanks

Brendan
 
Could you just do a validation where you attempt to find in the
filename string ".exe" or ".vbs" ?
 
Use this following expression : $(?<!\.(?:exe|vbs))
It means that you want a string finishing by something that is not a '.'
character followed by exe or vbs.
Explanations :
$ it's the end of the line or string
(?<! it's the backreference to say that you are looking backward for
something you do not want
\. it's the '.' character
(?: it's a non capturing block that permit the choice between exe
and vbs
exe it's the first extension to check
| it's the separator of the two extensions
vbs it's the second extension to check
) it's the end of the non capturing block
) it's the end of the backtracking

The following line will tell you if the file DOES NOT end with .exe or .vbs
:
Regex.IsMatch(maChaine,@"$(?<!\.(?:exe|vbs))")

Hope it helps,

Ludovic SOEUR.
 
Back
Top