PAN Card Number validation using JavaScript

 

Introduction: Hello Guys, “Welcome back” Today i am here with another one new great article. In this article I will explain about how to implement Indian PAN Card Number validation using JavaScript.

PAN Card Number will be entered in the TextBox by the user and it will be validate on the click of Button by using Regular Expression (Regex) in JavaScript.

Code for HTML Page

On the HTML page there i will place Textbox control for entering the PAN Number by the user. Here I will also place the control named span to show the message or error message. Here I will also place the control named button, on the click of button  Validation_PAN  function will be called to check the valid PAN Card entered by the user.

<input name="txt_PanCard" type="text" id="txt_PanCard" class="PAN" />

<span id="lbl_PanCard" class="error">Invalid PAN Number</span>

<br /><br />

<input type="button" id="btn_Submit" value="Submit" onclick="Validation_PAN()" />

Validate PAN Card Number using JavaScript

After button click a function named  Validation_PAN() will be called.  First, the PAN Card Number entered by the user will be send to the function and then its value will be validating using a Regular Expression. If the entered PAN Number format is incorrect then the Error Message will be displayed in SPAN.

<script type="text/javascript">

    function Validation_PAN() {

        var txtPANCard = document.getElementById("txt_PanCard");

        var lblPANCard = document.getElementById("lbl_PanCard ")

        var regex = /([A-Z]){5}([0-9]){4}([A-Z]){1}$/;

        if (regex.test(txtPANCard.value.toUpperCase())) {

            lblPANCard.style.visibility = "hidden";

            return true;

        } else {

            lblPANCard.style.visibility = "visible";

            return false;

        }

    }

</script>

 Here i am giving the complete code for HTML page. You can copy and paste the code on your HTML page and enjoy the execution of the code.

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title></title>

</head>

<body>

    <style type="text/css">

        body

        {

            font-family: Arial;

            font-size: 10pt;

        }

        .PAN

        {

            text-transform: uppercase;

        }

        .error

        {

            color: Red;

            visibility: hidden;

        }

    </style>

    PAN Card:

    <input name="txtPANCard" type="text" id="txt_PanCard" class="PAN" />

    <span id="lbl_PanCard" class="error">Invalid PAN Number</span>

    <br /><br />

    <input type="button" id="btn_Submit" value="Submit" onclick="Validation_PAN()" />

    <script type="text/javascript">

        function Validation_PAN() {

            var txtPANCard = document.getElementById("txt_PanCard");

            var lblPANCard = document.getElementById("lbl_PanCard")

            var regex = /([A-Z]){5}([0-9]){4}([A-Z]){1}$/;

            if (regex.test(txtPANCard.value.toUpperCase())) {

                lbl_PanCard.style.visibility = "hidden";

                return true;

            } else {

                lbl_PanCard.style.visibility = "visible";

                return false;

            }

        }

    </script>

</body>

</html>

Conclusion: In above code, I explained that how to implement Indian PAN Card Number (PAN) validation using JavaScript. This code is very helpful for every developer. Bye Bye and take care of you Developers. We will come back shortly with the new article.

Regards

Using Asp.net

 

Comments

Popular posts from this blog

Sending reset password link for one time use only in asp.net

add delete update inside gridview using store procedure in ASP.NET

Change password using asp.net