• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Group variable validation

 
sriraj anandhi
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
 
Merrill Higginson
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic