Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
heyy...

I want to validate the images on file upload(before upload) .I find a java script for this....here is the javascript ...

XML
<script type="text/javascript">
    $(function() {
    $('#<%=fileupload1.ClientID %>').change(
        function()

         {
            var fileExtension = ['jpeg', 'jpg', 'png', 'gif', 'bmp'];
            if ($.inArray($(this).val().split('.').pop().toLowerCase(), fileExtension) == -1)
                               alert("Only '.jpeg','.jpg', '.png', '.gif', '.bmp' formats are allowed.");


        })
    })
</script>



but want I face the problem is ..,I have 4 fileupload controls ..so for each I have to put separate javascript ..can this javascript handle in single javascript....??/
Posted
Updated 27-Feb-20 22:47pm
Comments
aravindnass 2-Jan-13 4:22am    
haiii....can I get the size checking(image is not exceed than 4MB)..with this javascript

Hi,

You can use the following,

XML
<script type="text/javascript">
    function fileCheck(obj) {
            var fileExtension = ['jpeg', 'jpg', 'png', 'gif', 'bmp'];
            if ($.inArray($(obj).val().split('.').pop().toLowerCase(), fileExtension) == -1)
                alert("Only '.jpeg','.jpg', '.png', '.gif', '.bmp' formats are allowed.");
    }
</script>


<asp:FileUpload ID="FileUpload1" runat="server"  onchange="fileCheck(this);"/>
 
Share this answer
 
Comments
aravindnass 2-Jan-13 4:21am    
haiii....can I get the size checking(image is not exceed than 4MB)..with this javascript
you can pass multiple ids to the jquery events, for example $("#segement1,#segement2,#segement3").change

Hope this helps!
 
Share this answer
 
Comments
aravindnass 2-Jan-13 4:22am    
haiii....can I get the size checking(image is not exceed than 4MB)..with this javascript
Rajesh Buddaraju 2-Jan-13 7:39am    
refer http://stackoverflow.com/questions/3717793/javascript-file-upload-size-validation

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900