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

whitespace validation??

 
Sumithab Baskaran
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need to write a custom validation using Regular expressions
 
Steve McCann
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no custom validation necessary. use the 'mask' rule and check using this regex: ^[0-9]*$ .
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh, and the mask rule's error message can be customized to say whatever you want.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic