Meaningless Drivel is fun!*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 1012
    
    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
 
Similar Threads
Spring MVC and Form Validation
valueChangelistener vs Javascript
getting data from the database with the non mandatory fields
Is use of reflection api encouraged?
Program action of a page dynamically depending on the link from where it is called