com.doyospy.core.annotation.EmailValidated Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doyospy-all Show documentation
Show all versions of doyospy-all Show documentation
Doyospy是一个小而全的基于SpringBoot的java工具类库,通过静态方法封装,方便开发者使用,降低学习成本并提升工作效率。
The newest version!
package com.doyospy.core.annotation;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 邮箱校验注解实现
* @author Robin
*/
public class EmailValidated implements ConstraintValidator {
private static final Pattern PATTERN = Pattern.compile("^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$");
@Override
public void initialize(Email email) {
}
@Override
public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
if (null != s) {
Matcher matcher = PATTERN.matcher(s);
return matcher.find();
}
return true;
}
}