今天会用了正则表达式
2015-09-09 18:38
225 查看
使用正则表达式判断输入的身份证信息!
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();
}
}
}
}
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();
}
}
}
}
相关文章推荐
- java生成二维码
- 李航博士的《浅谈我对机器学习的理解》 机器学习与自然语言处理
- 简单工厂模式
- iOS-runtime-根据协议名调某一个类有与协议里面放的相同的方法
- WebStorm 的使用(一)
- Windows Server 2016 技术预览 Hyper-V 新特性
- PullToRefreshListView 应用讲解
- IOS-跳转到设置页
- 椭圆识别
- Uvalive 6832 Bit String Reordering
- 值传递、指针传递、引用传递的区别
- Android进程间通信之使用Messenger
- java list两个接口可选择性判断包含元素
- hdu 1024 dp
- xmanger安装oracle调图形化界面报错解决方法
- springmvc3 拦截器,过滤ajax请求,判断用户登录,拦截规则设置
- 构建乘积数组
- Launcher App拖拽流程
- 黑马培训员_java02_面向对象
- UVA 11636 Hello World!