@NotNull
@Pattern(regexp="[[:Alpha:]]+", message="Only Alphabetic chars allowed")
protected String name;
这只允许 aaaa 作为输入,例如尝试将字符串设置为“apple”不起作用。但是将字符串设置为“aaaaaa”可以。我只想允许字母字符。
最佳答案
您可以使用:
@Pattern(regexp="\\p{Alpha}+", message="Only Alphabetic chars allowed")
关于JAVA,@Pattern(regex ="[[:Alpha:]]+")只允许aaaa而不是字母字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12538046/