一道jAVA题:身份证号必须是15或18位,手机必须是11位,座机必须以“-”链接,“-”前必须是4位数,“-”后

必须是7位,验证通过,方可注册成功,如果验证不通过,提示哪一步有错误。
(自己弄了半天用的是do-while结构,但是可能是判断条件出错了,希望能帮我解答)

import java.util.Scanner;
public class RegisterTest2 {
public static void main(String[] args){
Scanner input=new Scanner(System.in);
System.out.println("***欢迎进入注册系统***");
boolean finall;
do{
Register2 zhuce=new Register2();
System.out.println("请输入身份证:");
String IDCard=input.next();
System.out.println("请输入手机号:");
String Tel=input.next();
System.out.println("请输入座机号:");
String phone=input.next();
String[] num=new String[2];
num=phone.split("-");
String ch="-";
int index=phone.indexOf(ch);
int index2=phone.lastIndexOf(ch);
finall=zhuce.indexOf(IDCard, Tel, index, index2);
}while(finall);
System.out.println("注册成功!");
}
}

public class Register2 {
public boolean indexOf(String IDCard,String Tel,int index,int index2){
boolean flag=true;
if(IDCard.length()!=18&&IDCard.length()!=16){
System.out.println("身份证号必须是16位或18位!");
}else if(Tel.length()!=11){
System.out.println("手机号必须是11位!");
}else if(index!=4||index2!=12){
System.out.println("座机号码区号必须为4位,电话号码必须是7位!");
}else{
flag=false;
}
return flag;
}
}

**********希望能帮到你!****************
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-05-26
首先获取文本框的身份证号码,然后获取长度:文本框对象名.getText().length();
然后判断其长度是否为15或18位追问

非常感谢

追答

在main方法里面有一个while语句,因为while语句只有为真(true)的时候才会执行,

相似回答