当前位置: 首页> 房产> 建材 > 外贸公司名称大全简单大气_网站制作软件排名_百度的搜索引擎优化_网站测速

外贸公司名称大全简单大气_网站制作软件排名_百度的搜索引擎优化_网站测速

时间:2025/7/8 23:13:10来源:https://blog.csdn.net/slp20051002_/article/details/143366738 浏览次数:0次
外贸公司名称大全简单大气_网站制作软件排名_百度的搜索引擎优化_网站测速

        编写一个用户注册程序!需要注册用户名,密码,邮箱,手机号,并对输入的内容有
格式限制,都符合要求的话,才能显示注册成功。

import java.util.Scanner;
import java.util.regex.Pattern;
public class 注册 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String usernameRegex = "^[a-zA-Z][a-zA-Z0-9_]{4,11}$";
String passwordRegex = "^(?=.*[0-9])(?=.*[a-zA-Z]).{6,}$";
String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$";
String phoneRegex = "^1[3-9]\\d{9}$";boolean isRegistrationSuccessful = false;
while (!isRegistrationSuccessful) {
System.out.println("请输入用户名:");
String username = scanner.nextLine();
if (!username.matches(usernameRegex)) {
System.out.println("用户名格式不正确,用户名应为5-12位,字母开头,允许字母数字和下划线。请重新输入。");
continue;
}
System.out.println("密码:");
String password = scanner.nextLine();
if (!password.matches(passwordRegex)) {
System.out.println("密码格式不正确,密码至少6位,包含字母和数字。请重新输入。");
continue;
}
System.out.println("请输入邮箱:");
String email = scanner.nextLine();
if (!email.matches(emailRegex)) {
System.out.println("邮箱格式不正确,请重新输入。");
continue;}
System.out.println("请输入手机号:");
String phone = scanner.nextLine();
if (!phone.matches(phoneRegex)) {
System.out.println("手机号格式不正确,请输入正确手机号码。请重新输入。");
continue;
}isRegistrationSuccessful = true;
}
System.out.println("注册成功");
}
}

效果如图: 

关键字:外贸公司名称大全简单大气_网站制作软件排名_百度的搜索引擎优化_网站测速

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: