邮箱地址格式判断
-
@Pattern(regexp="^[a-zA-Z0-9_\\-]{2,}@[a-zA-Z0-9_\\-]{2,}(\\.[a-zA-Z0-9_\\-]+){1,2}$", message="邮箱地址格式错误")
@NotNull(message = "邮箱不能为空")
private String email;
-
final String email = "abc@163.com";
if (!Pattern.compile("^[a-zA-Z0-9_\\-]{2,}@[a-zA-Z0-9_\\-]{2,}(\\.[a-zA-Z0-9_\\-]+){1,2}$").matcher(email).find()) {
return "邮箱地址格式错误";
}
手机号格式判断
@Pattern(regexp="^[0-9]{11}$",message="手机号格式错误")
@NotNull(message = "手机号不能为空")
private String mobile;
final String mobile = "15512341234";
if (!Pattern.compile("^[0-9]{11}$").matcher(mobile).find()) {
return "手机号格式错误";
}
密码格式判断
@Pattern(regexp="^[0-9a-zA-Z_\\-\\*\\@\\`\\#\\!]{6,14}$",message="密码格式错误")
@NotNull(message = "密码不能为空")
private String password;
final String password = "1aA_-*@`#!";
if (!Pattern.compile("^[0-9a-zA-Z_\\-\\*\\@\\`\\#\\!]{6,14}$").matcher(password).find()) {
return "密码格式错误";
}
地图坐标格式判断
-
@Pattern(regexp="^[0-9\\.]{1,30}\\,[0-9\\.]{1,30}$",message="地图坐标格式错误")
@NotNull(message = "地图坐标不能为空")
private String mapPoint;
-
final String mapPoint = "31.44916171,121.58789949";
if (!Pattern.compile("^[0-9\\.]{1,30}\\,[0-9\\.]{1,30}$").matcher(mapPoint).find()) {
return "地图坐标格式错误";
}
如果您觉得有帮助,欢迎点赞哦 ~ 谢谢!!