开发者

how to validate integers or Long values,so that it should accept only numbers not characters using annotations in Hibernate?

I have a Command Class as below

public class DistrictCommand {
private Integer districtId;
@NotBlank
private String code;
@NotBlank
@RegExp("^[A-Za-z]*[A-Za-z]$")
private String name;
@NotBlank
开发者_运维知识库private String stateName;
@NotNull
private Long pincode;

}

Here i want to validate the pincode,if i leave the pincode field empty,am getting message as specified in resource bundle, but if i want to validate it that, it should only accept numbers and no characters, what annotation should i use? and also if i enter only 1 number it should display as enter exact 6 digits or min 0f 4 digits.

@Min and @Max validate the range but not the number of digits entered? how to do this....Kindly help me ???pl ...


@Min and @Max validate the range but not the number of digits entered? how to do this....Kindly help me ???pl ...

That's because a pin code can have meaningful leading zeros. You'd better consider it as a string with a ^[0-9] regexp. It does not have to be a number really. It is a number in real life because it is entered through numeric keypads.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜