Advertisement
SMASIF

Image/PDF Format & Size Validation

Nov 2nd, 2020
2,270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  $('#Signature').bind('change', function () {
  2.             //if (this.files[0].size > 4178944) {
  3.             //    alert("File size should not be more than 4 MB");
  4.             //    this.value = "";
  5.  
  6.             //}
  7.             var signatureUpload = $("#Signature")[0];
  8.             if (typeof (signatureUpload.files) != "undefined") {
  9.                     var reader = new FileReader();
  10.                     reader.readAsDataURL(signatureUpload.files[0]);
  11.                     reader.onload = function (e) {
  12.                         var image = new Image();
  13.                         image.src = e.target.result;
  14.                         image.onload = function () {
  15.                             height = this.height;
  16.                             width = this.width;
  17.                             if (height <= 80 && width <= 300) {
  18.  
  19.                             }
  20.                             else {
  21.                                 $("#Signature").val('');
  22.                                 alert('Signature Height and Width should be less than or equal 80 and 300');
  23.                             }
  24.  
  25.                         };
  26.                     }
  27.                 }
  28.             if (this.files && this.files[0] && this.files[0].name.match(/\.(jpg|jpeg|png|gif)$/)) {
  29.                 if (this.files[0].size > 1048576) {
  30.                     alert('File size is larger than 1MB!');
  31.                 }
  32.                 else {
  33.                     var reader = new FileReader();
  34.                     reader.onload = imageIsLoaded;
  35.                     reader.readAsDataURL(this.files[0]);
  36.                 }
  37.             } else {
  38.                 this.value = "";
  39.                 alert('This is not an image file!');
  40.             }
  41.            
  42.         });
  43.         $('#GSignature').bind('change', function () {
  44.             //if (this.files[0].size > 4178944) {
  45.             //    alert("File size should not be more than 4 MB");
  46.             //    this.value = "";
  47.  
  48.             //}
  49.             var signatureUpload = $("#GSignature")[0];
  50.             if (typeof (signatureUpload.files) != "undefined") {
  51.                     var reader = new FileReader();
  52.                     reader.readAsDataURL(signatureUpload.files[0]);
  53.                     reader.onload = function (e) {
  54.                         var image = new Image();
  55.                         image.src = e.target.result;
  56.                         image.onload = function () {
  57.                             height = this.height;
  58.                             width = this.width;
  59.                             if (height <= 80 && width <= 300) {
  60.  
  61.                             }
  62.                             else {
  63.                                 $("#GSignature").val('');
  64.                                 alert('Signature Height and Width should be less than or equal 80 and 300');
  65.                             }
  66.  
  67.                         };
  68.                     }
  69.                 }
  70.             if (this.files && this.files[0] && this.files[0].name.match(/\.(jpg|jpeg|png|gif)$/)) {
  71.                 if (this.files[0].size > 1048576) {
  72.                     alert('File size is larger than 1MB!');
  73.                 }
  74.                 else {
  75.                     var reader = new FileReader();
  76.                     reader.onload = imageIsLoaded;
  77.                     reader.readAsDataURL(this.files[0]);
  78.                 }
  79.             } else {
  80.                 this.value = "";
  81.                 alert('This is not an image file!');
  82.             }
  83.            
  84.         });
  85.  
  86.         $('#Image').bind('change', function () {
  87.             //if (this.files[0].size > 4178944) {
  88.             //    alert("File size should not be more than 4 MB");
  89.             //    this.value = "";
  90.  
  91.             //}
  92.             var signatureUpload = $("#Image")[0];
  93.             if (typeof (signatureUpload.files) != "undefined") {
  94.                     var reader = new FileReader();
  95.                     reader.readAsDataURL(signatureUpload.files[0]);
  96.                     reader.onload = function (e) {
  97.                         var image = new Image();
  98.                         image.src = e.target.result;
  99.                         image.onload = function () {
  100.                             height = this.height;
  101.                             width = this.width;
  102.                             if (height <= 300 && width <= 300) {
  103.  
  104.                             }
  105.                             else {
  106.                                 $("#Image").val('');
  107.                                 alert('Photo Height and Width should be less than or equal 300 and 300');
  108.                             }
  109.  
  110.                         };
  111.                     }
  112.                 }
  113.             if (this.files && this.files[0] && this.files[0].name.match(/\.(jpg|jpeg|png|gif)$/)) {
  114.                 if (this.files[0].size > 1048576) {
  115.                     alert('File size is larger than 1MB!');
  116.                 }
  117.                 else {
  118.                     var reader = new FileReader();
  119.                     reader.onload = imageIsLoaded;
  120.                     reader.readAsDataURL(this.files[0]);
  121.                 }
  122.             } else {
  123.                 this.value = "";
  124.                 alert('This is not an image file!');
  125.             }
  126.            
  127.         });
  128.         $('#NID').bind('change', function () {
  129.             //if (this.files[0].size > 4178944) {
  130.             //    alert("File size should not be more than 4 MB");
  131.             //    this.value = "";
  132.  
  133.             //}
  134.             var signatureUpload = $("#NID")[0];
  135.             if (typeof (signatureUpload.files) != "undefined") {
  136.                     var reader = new FileReader();
  137.                     reader.readAsDataURL(signatureUpload.files[0]);
  138.                     reader.onload = function (e) {
  139.                         var image = new Image();
  140.                         image.src = e.target.result;
  141.                         image.onload = function () {
  142.                             height = this.height;
  143.                             width = this.width;
  144.                             if (height <= 500 && width <= 500) {
  145.  
  146.                             }
  147.                             else {
  148.                                 $("#NID").val('');
  149.                                 alert('Photo Height and Width should be less than or equal 500 and 500');
  150.                             }
  151.  
  152.                         };
  153.                     }
  154.                 }
  155.             if (this.files && this.files[0] && this.files[0].name.match(/\.(jpg|jpeg|png|gif)$/)) {
  156.                 if (this.files[0].size > 1048576) {
  157.                     alert('File size is larger than 1MB!');
  158.                 }
  159.                 else {
  160.                     var reader = new FileReader();
  161.                     reader.onload = imageIsLoaded;
  162.                     reader.readAsDataURL(this.files[0]);
  163.                 }
  164.             } else {
  165.                 this.value = "";
  166.                 alert('This is not an image file!');
  167.             }
  168.            
  169.         });
  170.         $('#GImage').bind('change', function () {
  171.             //if (this.files[0].size > 4178944) {
  172.             //    alert("File size should not be more than 4 MB");
  173.             //    this.value = "";
  174.  
  175.             //}
  176.             var signatureUpload = $("#GImage")[0];
  177.             if (typeof (signatureUpload.files) != "undefined") {
  178.                     var reader = new FileReader();
  179.                     reader.readAsDataURL(signatureUpload.files[0]);
  180.                     reader.onload = function (e) {
  181.                         var image = new Image();
  182.                         image.src = e.target.result;
  183.                         image.onload = function () {
  184.                             height = this.height;
  185.                             width = this.width;
  186.                             if (height <= 300 && width <= 300) {
  187.  
  188.                             }
  189.                             else {
  190.                                 $("#GImage").val('');
  191.                                 alert('Photo Height and Width should be less than or equal 300 and 300');
  192.                             }
  193.  
  194.                         };
  195.                     }
  196.                 }
  197.             if (this.files && this.files[0] && this.files[0].name.match(/\.(jpg|jpeg|png|gif)$/)) {
  198.                 if (this.files[0].size > 1048576) {
  199.                     alert('File size is larger than 1MB!');
  200.                 }
  201.                 else {
  202.                     var reader = new FileReader();
  203.                     reader.onload = imageIsLoaded;
  204.                     reader.readAsDataURL(this.files[0]);
  205.                 }
  206.             } else {
  207.                 this.value = "";
  208.                 alert('This is not an image file!');
  209.             }
  210.            
  211.         });
  212.         $('#GNID').bind('change', function () {
  213.             //if (this.files[0].size > 4178944) {
  214.             //    alert("File size should not be more than 4 MB");
  215.             //    this.value = "";
  216.  
  217.             //}
  218.             var signatureUpload = $("#GNID")[0];
  219.             if (typeof (signatureUpload.files) != "undefined") {
  220.                     var reader = new FileReader();
  221.                     reader.readAsDataURL(signatureUpload.files[0]);
  222.                     reader.onload = function (e) {
  223.                         var image = new Image();
  224.                         image.src = e.target.result;
  225.                         image.onload = function () {
  226.                             height = this.height;
  227.                             width = this.width;
  228.                             if (height <= 500 && width <= 500) {
  229.  
  230.                             }
  231.                             else {
  232.                                 $("#GNID").val('');
  233.                                 alert('Photo Height and Width should be less than or equal 500 and 500');
  234.                             }
  235.  
  236.                         };
  237.                     }
  238.                 }
  239.             if (this.files && this.files[0] && this.files[0].name.match(/\.(jpg|jpeg|png|gif)$/)) {
  240.                 if (this.files[0].size > 1048576) {
  241.                     alert('File size is larger than 1MB!');
  242.                 }
  243.                 else {
  244.                     var reader = new FileReader();
  245.                     reader.onload = imageIsLoaded;
  246.                     reader.readAsDataURL(this.files[0]);
  247.                 }
  248.             } else {
  249.                 this.value = "";
  250.                 alert('This is not an image file!');
  251.             }
  252.            
  253.         });
  254.  
  255.         $('#Application').bind('change', function () {
  256.             if (this.files[0].size > 3679232) {
  257.                 alert("File size should be within 3.5 MB!!");
  258.                 this.value = "";
  259.  
  260.             }
  261.         });
  262.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement