注册程序的简单实现

package com.xuexi;


import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class ZhuCe {


    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,20})";
    private static final String IDS_PATTERN = "^4[0-9]{17}";
    private static String userName;
    private static String password;
    private static String confirmpasd;
    private static String ids;
    private static String mima = "";


    public static void main(String[] args) {
        java.util.Scanner sc = new java.util.Scanner(System.in);
        // String userName ;
        //String password ;
        System.out.println("-------------欢迎进入注册页面-----------------");
        while (true) {
            System.out.println("请输入账号:(手机号或邮箱)");
            userName = sc.nextLine();
            userName = userName.trim();
            Pattern pattern = Pattern.compile(USERNAME_PATTERN);
            Matcher matcher = pattern.matcher(userName);
            if(userName == null|| userName.length() ==0){
                System.out.println("账号不能为空!");
            }else if (matcher.matches()) {
                    //System.out.println("账号正确");
                    break;
                } else {
                    System.out.println("账号格式不正确!");
                }
            }


            while (true) {
                System.out.println("请输入密码:");
                password = sc.nextLine();
                Pattern pattern = Pattern.compile(PASSWORD_PATTERN);
                Matcher matcher = pattern.matcher(password);
                if (matcher.matches()) {
                    //System.out.println("您的密码符合要求");
                    mima = password;
                    break;
                } else {
                    System.out.println("您的密码不符合要求");
                }
            }


            while (true) {
                System.out.println("请输入确认密码:");
                confirmpasd = sc.nextLine();
                if (mima.equals(confirmpasd)) {
                    //System.out.println("密码正确");
                    break;
                } else {
                    System.out.println("密码不正确");
                }
            }


            while (true) {
                System.out.println("请输入身份证号:");
                ids = sc.nextLine();
                Pattern pattern = Pattern.compile(IDS_PATTERN);
                Matcher matcher = pattern.matcher(ids);
                if (matcher.matches()) {
                    System.out.println("注册成功");
                    break;
                } else {
                    System.out.println("身份证格式不正确");
                }


            }
        }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值