package RegularExpression.regex;
import java.util.Scanner;
/**
* FileName: RegExTest3
* Author: lps
* Date: 2022/4/13 14:02
* Sign:刘品水 Q:1944900433
*/
public class RegExTest3 {
public static void main(String[] args) {
//目标:校验手机号码 邮箱 电话号码 金额
//checkPhone();
//checkEmail();
//checkTel();
checkMoney();
}
public static void checkMoney(){
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("请您输入金额:");
String phone=sc.next();
if (phone.matches("\\d{0,12}(\\.\\d{0,10}){0,1}")){
System.out.println("金额格式正确 完成");
break;
}else {
System.out.println("您输入的格式有误 请重新输入");
}
}
}
public static void checkPhone(){
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 checkEmail(){
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,20}(\\.[a-zA-Z0-9]{2,20}){1,2}")){
System.out.println("邮箱号码格式正确 注册完成");
break;
}else {
System.out.println("您输入的格式有误 请重新输入");
}
}
}
public static void checkTel(){
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("请您输入注册的电话号码:");
String tel=sc.next();
if (tel.matches("0\\d{2,6}-?\\d{5,20}")){
System.out.println("电话号码号码格式正确 注册完成");
break;
}else {
System.out.println("您输入的格式有误 请重新输入");
}
}
}
}