November 1, 2008

Regular Expressions For Doc or Docx File

Regular Expressions For Doc or Docx File
There is no perfect method to restrict the user from uploading user some malicious file. one of the better way is to use the asp's regular expression validator.
id="RegularExpressionValidator1" runat="server"
ErrorMessage="Only .doc files are
allowed!"
ValidationExpression="^(([a-zA- Z]:)|(\\{2}\w+)\$?)(\\(\w[\w ].*))+(.doc|.DOC|.DOCX|.docx)$"
ControlToValidate="File1">



id="RequiredFieldValidator1" runat="server"
ErrorMessage="This is a required field!"
ControlToValidate="File1">

No comments: