• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Group variable validation

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guru's

I have a issue with a group variable validation using struts commons validation, any help will be appreciated.

I have a phone field (it is made of 4 text fields 3-3-4-5, last field being for extension)

eg. 646-787-7868-98989

I having tough time creating a validation rule for it.

the rules are:
1. All text fields should be numeric
2. Phone (all combined) is a required field
2. Ext field is optional

Please help.

thanks
raj
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just make the first 3 fields required and integer. The last field is integer.
 
sriraj anandhi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply, but my problem is I want to display the error message for the full phone number only once. As the the phone number is captured in separate fields I getting the error message four times.

Any help will be appreciated.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use the Struts validation framework and define four fields, you're going to get four error messages. There's no way around this with the "out of the box" validation framework.

You have 2 choices:

1-Remove the validation rules for all four fields. Then override the validate() method of your ActionForm. Manually code the logic for this validation, then call super.validate() to handle the other validation framework validations.

2-Create a custom validation rule that will handle this situation.

This link gives an example of how to code a custom validation rule.
 
Your mother is a hamster and your father smells of tiny ads!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic