Minimal Math Captcha JavaScript Library – jCaptcha.js

Category: Form , Javascript | May 25, 2020
Views Total:2,646 views
Official Page:Go to website
Last Update:May 25, 2020


Minimal Math Captcha JavaScript Library – jCaptcha.js


jCaptcha.js is a lightweight, vanilla JavaScript plugin that creates a simple, random, <canvas> based math captcha to protect against spam.

How to use it:

Insert the minified version of the jCaptcha.js library into the web page.

<script src="dist/index.min.js"></script>

Create an html form where you want to generate the math captcha.

<form class="form" action="">
  <input class="jCaptcha" type="text" placeholder="Type in result please">
  <button class="button" type="submit">Submit</button>

Initialize the math captcha.

var myCaptcha = new jCaptcha({
    // set callback function
    callback: function(response, $captchaInputElement) {
        if (response == 'success') {
            $captchaInputElement[0].placeholder = 'Submit successful!';
        if (response == 'error') {
            $captchaInputElement[0].placeholder = 'Please try again!';

Validate the math captcha on form submit.

document.querySelector('form').addEventListener('submit', function(e) {
  // captcha validate

Possible options with default values.

var myCaptcha = new jCaptcha({
    // CSS class of input field
    el: 'jCaptcha',
    // character for required value
    requiredValue: '*',
    // reset on error
    resetOnError: true,
    // focus on the input on error
    focusOnError: true,
    // clear on submit
    clearOnSubmit: true,
    // CSS class of canvas
    canvasClass: 'jCaptchaCanvas',
    // canvas styles
    canvasStyle: {
      width: null,
      height: null,
      font: '',
      fillStyle: '',
      textAlign: '',
      textBaseline: ''


v1.3.0 (05/25/2020)

  • Updated options
  • Resolved issue with multiple instances
  • Code improvements
  • Drop support for IE10


  • Update


  • Minor updates


  • v1.1.0

You Might Be Interested In:

2 thoughts on “Minimal Math Captcha JavaScript Library – jCaptcha.js

  1. NB

    Hi, I downloaded, but files are missing, where is jCaptcha.min.js ?


Leave a Reply