Tech Me More

To quench our thirst of sharing knowledge about our day to day experience & solution to techincal problems we face in our projects.

Advertise with us !
Send us an email at

Thursday, July 16, 2015

Java program to validate the PAN card Number : Regular expression

Write a java program to validate a PAN Card number. A PAN card number is said to be valid when it starts with 5 uppercase letters 4 digits and Followed by single upper case letter. A Valid PAN have only 10 letters.

For example: a pan card number AMEPJ2585B is valid where as AM525LDKF is invalid.

Given below is the java program which makes use of regular expressions to validate the PAN number.

import java.util.*;
class ValidPAN 
 public static void main(String[] args) 
  Scanner scn=new Scanner(;
  int t=scn.nextInt();
  String s[]=new String[t];
  boolean output[]=new boolean[t];
  for(int i=0; i<s.length;i++)
   boolean ss=s[i].matches("[A-Z]{5}\\d{4}[A-Z]{1}");
  for(boolean b:output)


Sample Output: 

No comments: