;

How to Validate if a PAN Card is valid or not in Jquery or Javascript


Tutorialsrack 16/03/2020 Jquery Javascript

In this article, we will learn how to validate if a pan card is valid or not in jquery or javascript. We are using Regular Expression to check if a PAN card is valid or not in JQuery or javascript.

Here is the function for validating if a PAN card is valid or not in Jquery or Javascript.

Example 1: Function to validate if a PAN card is valid or not in jquery

Example 1
// Function to validate if a PAN card is valid or not in jquery
function validatePAN(Pan) {
    var PAN_Card_No = Pan.toUpperCase();
    var regex = /([A-Z]){5}([0-9]){4}([A-Z]){1}$/;
    if (PAN_Card_No.length == 10) {
        if (PAN_Card_No.match(regex)) {
            return "Valid Pan Number";
        } else {
            return "InValid Pan Number";
        }
    } else {
        return "Enter Valid Pan Number";
    }
};

//Test Cases and Outputs

console.log(validatePAN('HSHFH8989L'));
// Output ==> "Valid Pan Number"

console.log(validatePAN('HSHFHQ989Q'));
// Output ==> "Valid Pan Number"

console.log(validatePAN('HSHS8989Q'));
// Output ==> "Enter Valid Pan Number"

// Entered PAN in lower Case
console.log(validatePAN('fdsdd8585d'));
// Output ==> "Valid Pan Number"

Example 2: Function to validate if a PAN card is valid or not in Javascript

Example 2
// Function to validate if a PAN card is valid or not in Javascript
function validatePAN(Pan) {
    var PAN_Card_No = Pan.toUpperCase();
    var regex = /([A-Z]){5}([0-9]){4}([A-Z]){1}$/;
    //value is tested using a Regular Expression.
    if (regex.test(PAN_Card_No)) {
        //If the enter PAN card Number format is correct then it returns true
        return true;
    } else {
        //If the enter PAN card Number format is correct then it returns false
        return false;
    }
};

//Test Cases and Outputs

console.log(validatePAN('HSHFH8989L'));
// Output ==> "it returns true"

console.log(validatePAN('HSHFHQ989Q'));
// Output ==> "it returns false"

console.log(validatePAN('HSHS8989Q'));
// Output ==> "it returns false"

// Entered PAN in lower Case
console.log(validatePAN('fdsdd8585d'));
// Output ==> "it returns true"

I hope this article will help you to understand how to validate if a pan card is valid or not in jquery or javascript.

Share your valuable feedback, please post your comment at the bottom of this article. Thank you!


Related Posts



Comments

Recent Posts
Tags