aspose file tools*
The moose likes Struts and the fly likes whitespace validation?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "whitespace validation??" Watch "whitespace validation??" New topic
Author

whitespace validation??

Sumithab Baskaran
Ranch Hand

Joined: Oct 29, 2004
Posts: 52
Hi All!

I am validating a text field which is an integer.

Here is the code:
<field property="dataFactoryFileId" depends="maxlength,integer">
<msg name="integer" key="fileSearchForm.dataFactoryFileId.integer" />
<arg0 key="fileSearchForm.dataFactoryFileId.displayname" /> <arg1 name="maxlength" key="${var:maxlength}" resource="false"/>
<var><var-name>maxlength</var-name><var-value>10</var-value></var>
</field>

When the user enters an integer like this: 2 0 9 6 9 5
Right now an error message is displayed: the field must be an integer.

How do I validate this and display an error message like - "do not use spaces while entering an integer"

Thanks in advance!
Vani Bandargal
Ranch Hand

Joined: Oct 06, 2005
Posts: 82
you need to write a custom validation using Regular expressions
Steve McCann
Ranch Hand

Joined: Oct 20, 2004
Posts: 81
Try swapping the two validations around so that it checks for a valid integer first. I have not tried it but I assume 2 3 4 is not a valid integer.

Steve
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
no custom validation necessary. use the 'mask' rule and check using this regex: ^[0-9]*$ .


-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
oh, and the mask rule's error message can be customized to say whatever you want.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

To avoid the extra spaces in submissions I use a Filter and RequestWrapper combination to trim all request parameter values. A submission of " " would get trimmed to "" and "88 " would get trimmed to "88". It really does the trick.

Note that my solution only takes care of leading and trailing spaces but the idea might help you to come up with a different kind of solution to the problem.
[ October 25, 2005: Message edited by: Marc Peabody ]

A good workman is known by his tools.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: whitespace validation??