Skip to content

Instantly share code, notes, and snippets.

@kudapara
Created April 24, 2019 20:51
Show Gist options
  • Save kudapara/45de50a818be07988cb81b3567d05e4b to your computer and use it in GitHub Desktop.
Save kudapara/45de50a818be07988cb81b3567d05e4b to your computer and use it in GitHub Desktop.
import java.util.regex.*;
public class NationalIdRegex {
public static void main(String args[]) {
// 1st way.
Pattern pattern = Pattern.compile("\\d{2}[-|\\t|\\s]\\d{7}[A-Za-z&&[^IOio]]\\d{2}");
Matcher matcher = pattern.matcher("29-1526374X45");
boolean isIdInCorrectFormat = matcher.matches();
System.out.println("Is the id correct: " + isIdInCorrectFormat);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment