Validate only if the field is not Null

百般思念 提交于 2019-12-01 08:24:12

Instead of using @Digit, I would like to suggest you to use @Pattern(message="YOUR_MESSAGE", regexp="REGULAR_EXPRESSION")

Main reason is that we show message for such set of values for which we want to restrict the user, here in your condition message is displayed for that value which you don't want to restrict.

So You wants to restrict user to enter anything other than blank space and numbers.Make a regular expression for that and use @Pattern with that.

For your case :

@Pattern(message="YOUR_MESSAGE", regexp="^(\\s*|\\d{10,15})$")

Obviously, you form submits empty strings instead of nulls. Just check the value of tpMobile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!