close

How can I validate google reCAPTCHA v2 using javascript/jQuery?

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How can I validate google reCAPTCHA v2 using javascript/jQuery? in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How can I validate google reCAPTCHA v2 using javascript/jQuery ?

  1. How can I validate google reCAPTCHA v2 using javascript/jQuery ?

    can I validate google reCAPTCHA v2 using javascript/jQuery if reCaptcha is not validated on client side grecaptcha.getResponse(); returns null, else is returns a value other than null.

  2. can I validate google reCAPTCHA v2 using javascript/jQuery

    can I validate google reCAPTCHA v2 using javascript/jQuery if reCaptcha is not validated on client side grecaptcha.getResponse(); returns null, else is returns a value other than null.

Method 1

This Client side verification of reCaptcha – the following worked for me :

if reCaptcha is not validated on client side grecaptcha.getResponse(); returns null, else is returns a value other than null.

Javascript Code:

var response = grecaptcha.getResponse();

if(response.length == 0)
    //reCaptcha not verified

else
    //reCaptch verified

Method 2

I used Palek’s solution inside a Bootstrap validator and it works. I’d have added a comment to his but I don’y have the rep;). Simplified version:

        $('#form').validator().on('submit', function (e) {
           var response = grecaptcha.getResponse();
           //recaptcha failed validation
           if(response.length == 0) {
               e.preventDefault();
               $('#recaptcha-error').show();
           }
           //recaptcha passed validation
           else {
               $('#recaptcha-error').hide();
           }
           if (e.isDefaultPrevented()) {
              return false;
           } else {
              return true;
           }
       });

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment