Java Digits Validation
java, model-view-controller, spring, validation
Solution
As you need the 6 digits, I think you should use a String to the property. If in some situations you need it as int, you make a
public int getIdOrder(){ return Integer.parseInt(idOrder);}
On the String you can use pattern validation. It would be somethind like this:
@Pattern(regexp="\\d{6}")
private String idOrder;
Another option, is keep the idOrder a int and make a getter for the string:
public String getIdOrgetAsString(){
String s = "000000" + idOrder;
return s.substring(s.length() - 6);
}
Anyway, there are some options.
Problem
I'm using validation in a int attribute: ``` @Digits(integer=6,fraction=0) private Integer idOrder; ``` But I wanted this attribute has exactly 6 digits. How can I do that? (Using JSP+Spring+Hibernate)