邮箱正则校验

master
李永杰 2024-04-19 22:02:29 +08:00
parent cccf0a2ba2
commit 748266f8db
1 changed files with 6 additions and 1 deletions

View File

@ -18,6 +18,8 @@ import com.muyu.system.remote.RemoteUserService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.regex.*;
/** /**
* *
@ -76,7 +78,10 @@ public class SysLoginService
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData()))
{ {
if(StringUtils.contains(username, "@")){ String emailRegex = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$";
Pattern pattern = Pattern.compile(emailRegex);
Matcher matcher = pattern.matcher(username);
if(!matcher.matches()){
recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "邮箱错误,请检查"); recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "邮箱错误,请检查");
throw new ServiceException("邮箱错误,请检查:" + username); throw new ServiceException("邮箱错误,请检查:" + username);
} }