How to implement image size validation in jquery?

Total Post:1

Points:7
JQuery 
C#
 411  View(s)
Ratings:
Rate this:

Hi,

I want to apply image size validation on image upload with the help of jquery.

Here is my code:

<div class="col-md-6">
        <label for="imageUpload">Upload Your Image</label>
        <input name="ContentImage" id="ContentImage" type='file' onchange="readURL(this);" style="background: none" />
</div>

Please give me some solution to achieve this task.

  1. Post:44

    Points:310
    Re: How to implement image size validation in jquery?

    Hi Indrajit,

    You can be achieved your task by following these steps:

    Step 1. First of all, create a method on button submit.

    Step 2. Now write following lines of code in your jquery method.

    if (typeof ($("#ContentImage")[0].files) != "undefined" && ContentImage != '') {
            var size = parseFloat($("#ContentImage")[0].files[0].size / 1024).toFixed(2);
            if (size > 500) {
                alert("Image Size Exceeded !!!");
                return false;
            }
        }

    I hope it's informative!!!

      Modified On Mar-19-2018 10:58:14 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!