0
@NotNull
@Pattern(regexp="[[:Alpha:]]+", message="Only Alphabetic chars allowed")
protected String name;

这仅允许 aaaa 作为输入,例如尝试将字符串设置为“apple”dosent 工作。但是将字符串设置为“aaaaaa”工作。我只想允许字母字符。

4

1 回答 1

2

你可以使用:

@Pattern(regexp="\\p{Alpha}+", message="Only Alphabetic chars allowed")
于 2012-09-21T21:06:40.153 回答