views:

27

answers:

2

i need to control Only ExcelFile uploading with RegularExpressionValidator How can i do that? i need to write a regex pattern in ValidationExpression...

 <h3>FileUpload Test</h3>
    <div>
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:Button id="UploadBtn" Text="Upload File" OnClick="UploadBtn_Click" runat="server" Width="105px" />
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        <asp:RegularExpressionValidator
id="FileUpLoadValidator" runat="server"
ErrorMessage="Upload Excel only."
ValidationExpression="([a-z]\w*)(.xlsx|.xlsm|.xls)$"
ControlToValidate="FileUpload1">
</asp:RegularExpressionValidator>
    </div>
A: 

ValidationExpression="[a-zA-Z0_9].*\bxlsx\b" is solution...

Phsika
It doesn't even allow a period in the file name.
Amarghosh
+2  A: 

I don't see why you'd validate the file name part - what's wrong about 123.abcd.xls? Just use

^.*\.xls[xm]?$
Amarghosh