Vaildate PAN Number in Java
In this tutorial, We will show you a simple program about, How to Validate PAN Number in Java program. The example program has been tested and shared in the same post.
PAN Number Verifier
package com.dineshkrish; /** * * @author Dinesh Krishnan * */ public class Utils { public static String PAN_REGX = "[A-Z]{5}\\d{4}[A-Z]{1}"; public static boolean verify(String panNumber) { if (panNumber != null && !panNumber.isEmpty()) { return panNumber.matches(PAN_REGX); } return false; } }
Testing the Program
package com.dineshkrish; /** * * @author Dinesh Krishnan * */ public class Test { public static void main(String[] args) { String[] panNumbers = { "ABBCD2212R", "EXAMT2223W", "BNAN44443E" }; for (String panNumber : panNumbers) { if (Utils.verify(panNumber)) { System.out.println(panNumber + " : " + "Valid"); } else { System.out.println(panNumber + " : " + "Invalid"); } } } }
Output
ABBCD2212R : Valid EXAMT2223W : Valid BNAN44443E : Invalid
More from my site

Hello, folks, I am a founder of idineshkrishnan.com. I love open source technologies, If you find my tutorials are useful, please consider making donations to these charities.
No responses yet