package com.itheima.convert;
import java.util.Scanner;
public class Test01 {
public static void main(String[] args) {
}
public static void checkEmail(){
Scanner sc=new Scanner(System.in);
while (true){
System.out.println("请输入您注册的手机号码");
String phone=sc.next();
if (phone.matches("1[3-9]\\d{9}")){
System.out.println("手机号码正确,注册完成");
break;
}else{
System.out.println("格式有误");
}
}
}
public static void checkPhone(){
Scanner sc=new Scanner(System.in);
while (true){
System.out.println("请输入您的邮箱:");
String email=sc.next();
//判断邮箱格式是否正确
if (email.matches("\\w{1,30}@[a-zA-Z0-9]{2,10}(\\.[a-zA-Z0-9]{2,20}){1,2}")){
System.out.println("邮箱格式正确");
break;
}else {
System.out.println("格式有误,");
}
}
}
}
JAVA基础----正则表达式校验邮箱和电话
最新推荐文章于 2024-08-01 03:49:39 发布