This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Spring and the fly likes integer (not mandatory) field validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Spring
Bookmark "integer (not mandatory) field validation" Watch "integer (not mandatory) field validation" New topic
Author

integer (not mandatory) field validation

Maverick Schueler
Greenhorn

Joined: Jun 18, 2013
Posts: 5
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

Joined: Nov 09, 2011
Posts: 1051
    
    5

How about annotating your phone number field as follows:

Obviously you can replace the max length 8 to suit your needs.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: integer (not mandatory) field validation
 
It's not a secret anymore!