Question

I want to maintain length of contact number(Like mobile number in between 10 and 12 digits number ). When I used String type I got but it allows alphabets along with numbers also. I want to prevent alphabets. How can I do with integer.

Below is my code:

@StringLengthFieldValidator(type=ValidatorType.FIELD,message="contact should contain min
of 10 numbers and max 12 numbers",minLength="10",maxLength="12")
private String contact;

Now I want for Integer type to do the same as above. How can I do

@ ?
private int contact;
Was it helpful?

Solution

You can do it with regex field validator. It validates numbers against the given pattern.

@RegexFieldValidator(regex = "\\d{10,12}", message="contact should contain min
of 10 numbers and max 12 numbers")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top