问题
@Pattern(regexp="^\\w{8,}")
private String username;
This pattern can only consist of numbers, letters and the underscore character.
How can I add the dot (.) to the pattern
Thanks
回答1:
Try this, it might be easier to understand if you explicitly define all valid characters:
@Pattern(regexp="^[A-Za-z0-9_.]{8,}")
private String username;
回答2:
You need to add end of the line anchor also.
@Pattern(regexp="^[.\\w]{8,}$")
来源:https://stackoverflow.com/questions/29515276/how-to-add-dot-to-regex