今天会用了正则表达式

来源:互联网 发布:手机语音骂人软件 编辑:程序博客网 时间:2024/05/16 19:28

使用正则表达式判断输入的身份证信息!

public static boolean cardno() {

System.out.println("——————————购买彩票——————————");
System.out.println("请输入身份证号:");
String c = sc.nextLine();
String checkid = "(^\\d{18}$)|(^\\d{15}$)";
if (c.length() == 18 || c.matches(checkid) == true) {
System.out.println("身份证信息正确!");
System.out.println("请核对您的身份证信息:" + c);
return true;
} else {
System.out.println("您输入的身份证信息不正确,!请重新输入!");
}
return false;
}

}



Test中


public class TestLottery {


static Lottery test = new Lottery();
static Scanner sc = new Scanner(System.in);


public static void main(String[] args) {
while (true) {
// 验证身份证信息
if(Lottery.cardno()==true){

// 随机输入7个数字
test.buyno();
// 随机生成7个中奖号码
test.randomno();
// 进行比对,根据中奖号码的个数兑奖
test.winmo();
}
}


}
}

0 0