In this tutorial, we will be discussing about pan card validation using JavaScript. PAN cards are an important document in India and are required for various financial transactions. Hence, it is important to ensure that the PAN number is valid before accepting it. There are few different ways to validate a PAN card number.
- One way is to use a regular expression, This approach can be used to validate the format of the PAN number, but cannot be used to verify its authenticity .
- Another way to validate a PAN number is by checking its checksum. The checksum is calculated using a specific algorithm and can be used to verify the accuracy of the PAN number.
Structure of PAN card:
The structure of pan card in India as it follows for example : ADSGJ9999A
- First five characters are letters (A-Z)
- next 4 numeris (0-9)
- last character letter (A-Z)
The Valid PAN card number must satisfy the following conditions they are:
- It should be ten characters long.
- The first five characters should be any upper case alphabets.
- The next four characters should be any number from 0 to 9.
- The last(tenth) character should be any upper case alphabet.
- It should not contain any white spaces.
Example of Pan card number validation using JavaScript
It contains HTML code for a web form that validates a PAN card number entered by the user using a JavaScript function. The form collects a user’s name, age, and 10-character PAN card number. When submitted, the JavaScript function checks if the PAN card number is exactly 10 characters and matches the specified regular expression pattern for a valid PAN format. It then displays an alert notifying the user if the number is valid or invalid.
<html> <head> <title>PANCARD VALIDATION</title> <script language="javascript"> function alphanum() { var pno=frm.pan.value; var patt=/^([A-Z]){5}([0-9]){4}([A-Z]){1}$/; if(pno.length!=10) { alert("Pancard number should be of 10 characters"); } else if(pno.match(patt)) { alert("You have entered your Pancard number properly"); } else { alert("Wrong Pancard number"); } } </script> </head> <body align="center" bgcolor="white"> <center> <h1>PANCARD VALIDATION USIGN JAVASCRIPT</h1> <form name="frm"> <table> <tr> <td> Enter Name:</td> <th><input type="text" name="name"></th> </tr> <tr> <td>Enter Age:</td> <th><input type="text" name="age"></th> </tr> <tr> <td>Enter Pancard Number:</td> <th><input type="text" name="pan" maxlength=10 placeholder="Like BBHPM5672K"></th> </tr> </table> <input type="submit" name="submit" value="SUMBIT"onclick="alphanum()"> </form> </center> </body> </html>
OUTPUT:
NANDH1234M is valid number DFDFJ86743IT is an invalid number
Conclusion
In conclusion, we learned how to validate pan card number using JavaScript. As it is important and required one for various financial transactions. for validating a PAN (Permanent Account Number) card number we need to ensure that the input follows the correct format then only it is valid otherwise it will be invalid.