【发布时间】:2017-05-26 13:56:42
【问题描述】:
我正在使用 bean 验证规范来验证我在 spring-boot thymeleaf 项目中的表单。 我的实体属性如下。
@NotEmpty(message = "{Password should not be empty}")
@Pattern(regexp = //Pattern for range 1-20, message = "{Wrong Input}")
private String password;
当我以空值运行并输入表单的密码字段时,会显示两个验证错误消息。
我的期望是,当输入空值时,只有@NotEmpty 注释应该起作用,另一方面,用户输入时应该只显示@Pattern 是错误的。
我该如何使用 Bean 验证规范呢?
问候。
【问题讨论】:
-
你能说明你在@Pattern 中使用的正则表达式模式吗?
-
@Gaurav 我在源代码中使用的实际模式是 (?=.*[0-9])(?=.*[az])(?=.*[ AZ])(?=\\S+$).{8,20}
-
你能给出一个你希望通过这个正则表达式的示例字符串吗?
-
这是示例字符串 test123User
标签: java spring spring-boot thymeleaf bean-validation