身份證正則表達式
檢測身份證是否合法
import java.util.*;
public class ifLegal{
String sex;
String birthday;
static Boolean islegal;
public static Boolean judgeLegal(String IDnum) {
String regex = "[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(10|11|12))([0-2][1-9]|30|31)\\d{3}[0-9Xx]";
if(IDnum.length()!=18) {
islegal=false;
return false;
}
if(!IDnum.matches(regex)) {
return false;
}
return true;
}
public static void main(String []args) {
System.out.println("請輸入身份證號");
Scanner reader = new Scanner(System.in);
String number = reader.nextLine();
Boolean judgeresult = judgeLegal(number);
if(judgeresult) {
System.out.println("輸入合法");
}
else
{
System.out.println("輸入有誤");
}
}
}
特別注意:
僅供參考學習,轉載請附上原文鏈接
分享學習心得,如有侵權,望聯繫本人處理
還在讀大學的程序員,項目經驗少,如有紕漏,感謝指正
需要源代碼請聯繫本人
謝謝配合
如果這篇文章對您有幫助,小小的點個贊,算是給小學弟的鼓勵吧!謝謝大佬!!/呱呱.jpg