Socket
Socket
Sign inDemoInstall

validpic.js

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    validpic.js

Javascript image validator based on mimetypes.


Version published
Weekly downloads
2
Maintainers
1
Created
Weekly downloads
 

Readme

Source

validPic.js

Javascript image validator based on mimetypes.

Introduction

Tired of not finding any library to validate images on the client side I decided to create one for my own use. Yeah, we all know client side validation is just one of the steps and we should never rely only on it, but hey! I helps, not only us but also users!

This library makes use of the magic numbers to detect different mimetypes, thefore even when the mimetype is mnodifed we can still figure out it it is what it claims to be.

Usage

Valid image types at the moment are: png, jpg, gif, bmp`.

  • Include the script before the closing </body> tag.
  • Use the class valid-pic in any input you want to validate.
  • Use the the custom events to manage errors in your own way

Example

<div>
    <input type="file" id="add-image" class="valid-pic" />
</div>

###Using javascript

document.getElementById('add-image').addEventListener("error", function(){
    console.log("Invalid image - javascript custom event");

    //do whatever here
}, false);

###Using jQuery

$('.valid-pic').on('error', function(e){
    var data = e.originalEvent.detail;

    console.log(data);
    console.log("Invalid image - jQuery custom event");
    
    $(data.input).css('background', 'red');
    $(data.input).after('<span class="error-message">Invalid image type!</div>');
});

Keywords

FAQs

Last updated on 12 Apr 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc