注册代码
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class zhanghao {
private static final String USERNAME_PATTERN = "^1[0-9]{10}|\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
//账号:手机号或者邮箱
private static final String PASSWORD_PATTERN = "((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{6,15})";
//密码:6-15 必须包含大小写字母和数字
private static final String ID_PATTERN = "^4[0-9]{17}|4[0-9]{16}x$";
//身份证:必须以4开头,末尾可以是x
private static Object mima;
public static void main(String[] args) {
String mima = "";
System.out.println("---------------***注册账号***-------------");
Scanner sc = new Scanner(System.in);
//注册账号
while (true) {
System.out.print(" 请输入账号:\n");
String username = sc.nextLine();
Pattern pattern = Pattern.compile(USERNAME_PATTERN);
Matcher matcher = pattern.matcher(username);
if (matcher.matches()) {
break;
} else {
System.out.println(" 你的账号格式不正确\n(请输入手机号或者邮箱)");
}
}
//密码判断
while (true) {
System.out.print("请输入密码:");
String Password1 = sc.nextLine();
Pattern pattern = Pattern.compile(PASSWORD_PATTERN);
Matcher matcher = pattern.matcher(Password1);
if (matcher.matches()) {
//System.out.println("注册成功!");
mima = Password1;
break;
} else {
System.out.println("你的密码格式不正确");
}
}
//确认密码判断
while (true) {
System.out.print("请确认密码:");
String Password2 = sc.nextLine();
if (mima.equals(Password2)) {
//System.out.println("你的密码正确");
break;
} else {
System.out.println("你的密码不正确");
}
}
//身份证判断
// boolean d = true;
while (true) {
System.out.print("请输入身份证:");
String id = sc.nextLine();
Pattern pattern = Pattern.compile(ID_PATTERN);
Matcher matcher = pattern.matcher(id);
if (matcher.matches()) {
System.out.println("\n注 册 成 功!");
break;
} else {
System.out.println("你的身份证格式不正确");
}
}
}
}
注册代码
最新推荐文章于 2019-10-19 20:35:58 发布