尝试其中任何一个。
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="Only JPG/jpg file allowed!"
ControlToValidate="ctlFileUpload"
ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w](.)*))+(\.jpg|\.JPG)$"
Width="510px" CssClass="Validator"></asp:RegularExpressionValidator>
// - - -或者
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="Only JPG/jpg file allowed!"
ControlToValidate="ctlFileUpload"
ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.jpg|.JPG)$"
Width="510px" CssClass="Validator"></asp:RegularExpressionValidator>
// - - - -或者
<asp:RegularExpressionValidator ID="imgValidator" runat="server" ControlToValidate="imgUpload"
ErrorMessage="*JPG/JPEG/GIF files only" ValidationExpression="^.+\.(([jJ][pP][eE]?[gG])|([gG][iI][fF]))$" />
或尝试此以允许用户上传 txt 文件
<asp:RegularExpressionValidator ID="FileUpLoadValidator" runat="server" ErrorMessage="Only text files!"
ValidationExpression=".*(\.txt|\.TXT)$" ControlToValidate="FileUpload1" Display="None">