• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

whitespace validation??

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you need to write a custom validation using Regular expressions
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh, and the mask rule's error message can be customized to say whatever you want.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic