How to implement image size validation in jquery?

Total Post:1

 615  View(s)
Rate this:


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" />

Please give me some solution to achieve this task.

  1. Post:44

    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


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.