Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

integer (not mandatory) field validation

 
Maverick Schueler
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spring MVC 3

I have a form with an integer form bean field (e.g. phoneNumber). This field is not mandatory. but I need to have it only digits (e.g. 0111234567890)
But whenever I keep the field blank, Spring treats it as String and throws exception.

Is there any way we can achieve this?
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about annotating your phone number field as follows:

Obviously you can replace the max length 8 to suit your needs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic