Image validations for file upload using regular expression validator in asp.net

In this article, we are validating the image type for file upload using asp.net validator, for this we have use the regular expression validator.
ValidationExpression="^ ([0-9a-zA-Z_\-~ :\\])+( .jpg|.JPG|.jpeg|.JPEG|.bmp|.BMP|.gif|.GIF|.png|.PNG)$"


Source code:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="imageuploader.aspx.cs" Inherits="imageuploader" %>


<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title> validate image using file upload </title>
   
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <fieldset style="width: 350px;">
            <legend>How to validate image using file upload</legend>
            <asp:FileUpload ID="FileUpload1" runat="server" />
            <br />
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
                ControlToValidate="FileUpload1"
                ErrorMessage="only jpeg,jpg,gif,bmp image allow" ForeColor="Red"
                ValidationExpression="^([0-9a-zA-Z_\-~ :\\])+(.jpg|.JPG|.jpeg|.JPEG|.bmp|.BMP|.gif|.GIF|.png|.PNG)$"></asp:RegularExpressionValidator>
        
        </fieldset>
    </div>
    </form>
</body>
</html>

Out-put:-



For More:-
Image validations for file upload using java script
Image validations for file upload using regular expression validator in asp.net Image validations for file upload using regular expression validator in asp.net Reviewed by NEERAJ SRIVASTAVA on 1:56:00 PM Rating: 5

No comments:

Powered by Blogger.