package com.youchain.utils;

import cn.hutool.core.util.RandomUtil;
import com.youchain.exception.BadRequestException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Component
@Slf4j
public class RegexUtils {
    public  static void  emailRegex(String input){
        if(input==null){
            throw new BadRequestException("邮件收件人必填");
        }
        String[] emails=input.split(";");
        for(int i=0;i<emails.length;i++){
            String email=emails[i];
            String regex = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(email);
            if (!matcher.matches()) {
                throw new BadRequestException(email+"请输入正确的邮件格式！");
            }
        }
    }

}
