blogspot visit counter

Saturday, 3 August 2013

Regular expression validator for image file extension

Regular expression image file extension

Introduction :- 
In this article i have explained how to validate image using Regular Expression Validator  in  before upload in data base or image fonder.In my previous article  i have explained  Different Validation Control in Like this :- How to allow numeric values into textbox , How to upload multiple photo using , Control With Example , Jquery form validation in , JavaScript validation for grid view footer textbox , JavaScript validation for grid view in edit mode

 Description :- 

 In this Post I have created a new  project and add use a Regular Expression Validator in as show below

step 1 -    Create a  new project .
Step 2 -   Write Click on project explorer and add a new form .
Step 3 -   Drag and drop a RegularExpressionValidator and file upload control on the page.
Step 4 -   Drap and drop a  button on the web  page for save the image on click button in the image folder.
Step 5-    Write Click and add new folder in your project.

Now set the property for validate the image using RegularExpressionValidator  as show below

Control to validate =FileUploade
Text = Invalid image icon
 ValidationExperssion  =^.*\.((j|J)(p|P)(e|E)?(g|G)|(g|G)(i|I)(f|F)|(p|P)(n|N)(g|G))$"

 Complete Code as show below

<head runat="server">
    <form id="form1" runat="server">
        <asp:FileUpload ID="File1" runat="server" />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Upload" />
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
            ControlToValidate="File1" ForeColor="Red"
            ValidationExpression="^.*\.((j|J)(p|P)(e|E)?(g|G)|(g|G)(i|I)(f|F)|(p|P)(n|N)(g|G))$">Invalide file !</asp:RegularExpressionValidator>

Output image as show below

Download sample code attached

1 comment:

  1. This comment has been removed by a blog administrator.


Related Posts Plugin for WordPress, Blogger...