Which annotation to use for only accept number as input?

carpi :

The registration field below should only accept number. Which annotation should I use? I made a research and people were talking about @Digits and @Pattern but I'm not sure that this is what I need

@Length(min=13, max=13)
private Long registration;
Alien :

The parameter type is Long so it will only accept numbers you don't even have to validate it.

You can validate for different purposes like below.

If it should accept only positive numbers.

@Min(value = 0L, message = "The value must be positive")
private Long value;

Or using regex pattern.

@Pattern(regexp = "[\\s]*[0-9]*[1-9]+",message="msg")

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=403962&siteId=1