import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegisterCheck {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("用户名:");
String name=sc.nextLine();
boolean flag=false;
do {
String resname="^\\w{6,}$";
if (!name.matches(resname)) {
System.out.println("用户名为字母、数字、下划线,不能为空或小于6个字符");
System.out.println("用户名:");
name=sc.nextLine();
flag=true;
}else {
flag=false;
}
} while (flag);
/*
* 密码加密、验证
*/
System.out.println("密码:");
String pwd=sc.nextLine();
do {
if (pwd.length()>=3) {
StringBuffer pwdBuffer=new StringBuffer();
StringBuffer pwd1=pwdBuffer.append(pwd);
pwd1.insert(3, "alo");
pwd1.append("63");
pwd1.reverse();
String respwd="\\w{11,}";
if (!pwd1.toString().matches(respwd)) {
System.out.println("密码为字母、数字、下划线,不能为空或小于6个字符");
System.out.println("密码:");
pwd=sc.nextLine();
flag=true;
}else {
flag=false;
}
}else {
System.out.println("密码必须超过6位");
System.out.println("密码:");
pwd=sc.nextLine();
flag=true;
}
} while (flag);
System.out.println("昵称:");
String nickname=sc.nextLine();
do {
String resnickname = "\\w{6,}";
if (!nickname.matches(resnickname)) {
System.out.println("昵称为字母、数字、下划线,不能为空或小于6个字符");
System.out.println("昵称:");
nickname=sc.nextLine();
flag=true;
}else {
flag=false;
}
} while (flag);
System.out.println("中文名字:");
String namech=sc.nextLine();
do {
String pattern="[\u4e00-\u9fa5]+";
if (!namech.matches(pattern)) {
System.out.println("中文名字必须是中文");
System.out.println("中文名字:");
namech=sc.nextLine();
flag=true;
} else {
flag=false;
}
} while (flag);
System.out.println("手机号:");
String phone=sc.nextLine();
do {
String resphoneString="[1-9]{1}\\d{10}";
if (!phone.matches(resphoneString)) {
System.out.println("手机号必须全为数字且第一位不为0");
System.out.println("手机号:");
phone=sc.nextLine();
flag=true;
}else {
flag=false;
}
} while (flag);
System.out.println("邮箱:");
String Email=sc.nextLine();
do {
String resemail="\\w+@\\w{2,3}\\.com|cn|net";
if (!Email.matches(resemail)) {
System.out.println("邮箱格式不正确!!!");
System.out.println("邮箱:");
Email=sc.nextLine();
flag=true;
}else {
System.out.println("注册成功!!!!");
flag=false;
}
} while (flag);
}
}
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegisterCheck {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("用户名:");
String name=sc.nextLine();
boolean flag=false;
do {
String resname="^\\w{6,}$";
if (!name.matches(resname)) {
System.out.println("用户名为字母、数字、下划线,不能为空或小于6个字符");
System.out.println("用户名:");
name=sc.nextLine();
flag=true;
}else {
flag=false;
}
} while (flag);
/*
* 密码加密、验证
*/
System.out.println("密码:");
String pwd=sc.nextLine();
do {
if (pwd.length()>=3) {
StringBuffer pwdBuffer=new StringBuffer();
StringBuffer pwd1=pwdBuffer.append(pwd);
pwd1.insert(3, "alo");
pwd1.append("63");
pwd1.reverse();
String respwd="\\w{11,}";
if (!pwd1.toString().matches(respwd)) {
System.out.println("密码为字母、数字、下划线,不能为空或小于6个字符");
System.out.println("密码:");
pwd=sc.nextLine();
flag=true;
}else {
flag=false;
}
}else {
System.out.println("密码必须超过6位");
System.out.println("密码:");
pwd=sc.nextLine();
flag=true;
}
} while (flag);
System.out.println("昵称:");
String nickname=sc.nextLine();
do {
String resnickname = "\\w{6,}";
if (!nickname.matches(resnickname)) {
System.out.println("昵称为字母、数字、下划线,不能为空或小于6个字符");
System.out.println("昵称:");
nickname=sc.nextLine();
flag=true;
}else {
flag=false;
}
} while (flag);
System.out.println("中文名字:");
String namech=sc.nextLine();
do {
String pattern="[\u4e00-\u9fa5]+";
if (!namech.matches(pattern)) {
System.out.println("中文名字必须是中文");
System.out.println("中文名字:");
namech=sc.nextLine();
flag=true;
} else {
flag=false;
}
} while (flag);
System.out.println("手机号:");
String phone=sc.nextLine();
do {
String resphoneString="[1-9]{1}\\d{10}";
if (!phone.matches(resphoneString)) {
System.out.println("手机号必须全为数字且第一位不为0");
System.out.println("手机号:");
phone=sc.nextLine();
flag=true;
}else {
flag=false;
}
} while (flag);
System.out.println("邮箱:");
String Email=sc.nextLine();
do {
String resemail="\\w+@\\w{2,3}\\.com|cn|net";
if (!Email.matches(resemail)) {
System.out.println("邮箱格式不正确!!!");
System.out.println("邮箱:");
Email=sc.nextLine();
flag=true;
}else {
System.out.println("注册成功!!!!");
flag=false;
}
} while (flag);
}
}