【问题标题】:Hibernate Validator (how to only accept a 4 letters and 10 digits)Hibernate Validator(如何只接受 4 个字母和 10 个数字)
【发布时间】:2016-05-03 10:52:31
【问题描述】:

我正在尝试使用这种格式(4 个字母和 10 个数字)验证 String

ABCD1234567890

但是这段代码不起作用

@NotNull(message="tarjeta sanitaria cannot be null")
@Pattern(regexp = "(([A-Z]){4})([0-9]){10}",message = "tarjeta sanitaria is not valid")
private String tarjSanitaria;

有什么想法吗?

【问题讨论】:

  • 代码在什么情况下不工作?

标签: java regex hibernate hibernate-validator


【解决方案1】:

我认为您错过了模式中字符串的开头和结尾。

也许这就是你要找的东西:

^[A-Z]{4}[0-9]{10}$

您可以使用此页面https://regex101.com/ 测试您的正则表达式

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-17
    • 1970-01-01
    • 1970-01-01
    • 2020-12-02
    • 2014-09-09
    • 2014-06-06
    • 1970-01-01
    • 2012-01-09
    相关资源
    最近更新 更多