Created
April 24, 2019 20:51
-
-
Save kudapara/45de50a818be07988cb81b3567d05e4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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