Commit 45289a21 by zwb

添加手机号邮箱校验

parent 297d8c34
......@@ -3,6 +3,8 @@ import java.lang.reflect.Field;
import java.util.Date;
import com.google.common.collect.Maps;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
......@@ -19,6 +21,7 @@ import org.apache.poi.ss.formula.functions.T;
import org.dromara.common.core.constant.CacheConstants;
import org.dromara.common.core.domain.UserLoginInfo;
import org.dromara.common.core.enums.ResumeEnum;
import org.dromara.common.core.exception.WarnException;
import org.dromara.common.core.utils.JsonToObjectMapper;
import org.dromara.common.core.utils.SnowFlakeUtil;
import org.dromara.common.core.utils.StringUtils;
......@@ -31,6 +34,8 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Slf4j
@Service
......@@ -692,6 +697,9 @@ public class NewEditionResumeUtil {
public void updateBaseInfo(ResumeMakeDto resumeMakeDto, Long userId) {
FunctionResumeBase resumeBase = JsonToObjectMapper.mapJsonToObject(JSONObject.parseObject(JSON.toJSONString(resumeMakeDto.getBodyData())),
FunctionResumeBase.class);
if (validateChineseMobile(resumeBase.getPhone())){
throw new WarnException("手机号格式不正确");
}
resumeBase.setResumeName(resumeMakeDto.getResumeName());
resumeBase.setId(Long.valueOf(resumeMakeDto.getResumeId()));
resumeBase.setUserId(userId);
......@@ -718,6 +726,80 @@ public class NewEditionResumeUtil {
resume.resumeCacheService.saveResumeModelDataCache(resumeBase.getId(), resumeBase.getId(), JSON.toJSONString(resumeBase));
}
// 更严格的RFC 5322实现
private static final String STRICT_EMAIL_REGEX =
"^(?=.{1,64}@)[A-Za-z0-9_-]+(\\.[A-Za-z0-9_-]+)*@" +
"[^-][A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$";
private static final Pattern STRICT_EMAIL_PATTERN =
Pattern.compile(STRICT_EMAIL_REGEX, Pattern.CASE_INSENSITIVE);
/**
* 邮箱校验
* @param email
* @return
*/
public boolean validateEmailStrict(String email) {
if (email == null || email.trim().isEmpty()) {
return false;
}
String emailStr = email.trim();
// 长度检查
if (emailStr.length() > 254) {
return false;
}
String[] parts = emailStr.split("@");
if (parts.length != 2) {
return false;
}
String localPart = parts[0];
String domain = parts[1];
// 本地部分长度检查(RFC 5321限制)
if (localPart.length() > 64) {
return false;
}
// 域名长度检查
if (domain.length() > 253) {
return false;
}
// 不允许连续的点
if (emailStr.contains("..")) {
return false;
}
// 本地部分不能以点开头或结尾
if (localPart.startsWith(".") || localPart.endsWith(".")) {
return false;
}
return STRICT_EMAIL_PATTERN.matcher(emailStr).matches();
}
/**
* 手机号校验
*/
public Boolean validateChineseMobile(String phone) {
if (phone == null || phone.trim().isEmpty()) {
return false;
}
// 去除空格和特殊字符
String cleanPhone = phone.replaceAll("\\s+|-", "");
// 正则表达式:1开头,第二位3-9,总共11位
Pattern pattern = Pattern.compile("^1[3-9]\\d{9}$");
Matcher matcher = pattern.matcher(cleanPhone);
return matcher.matches();
}
/**
* 修改自定义模块信息
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment