• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts validator-rules.xml regex problem

 
Amieya Prabhaker
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have a rule for bank accounts set as ^[0-9]{6,8}$ in validator-rules.xml

That is to say the account number is 6 to 8 digits long and takes in numbers 0-9. The full text is as under:

<constant><constant-name>accountno</constant-name> <constant-value>^[0-9]{6,8}$</constant-value></constant>

I want to add in an additional constraint that the account number should be non-zero; so someone should not try entering in 000000, 0000000 or 00000000 since the current regex above will allow these to be entered.

Can you please suggest the change required to the regex pattern to achieve this.
Thanks.
P.S: Corresponding validation.xml and other files are set up correctly.
 
Amieya Prabhaker
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any struts/ regular expressions gurus out here.

I have tried some sort of -(000000) kind of pattern; i.e. above pattern minus the all zeros case, but it does not work.

Thanks.
 
Amieya Prabhaker
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder if this problem can be fixed using the intRange in validation.xml rather than the regex in validator-rules.xml

Greatly appreciate any struts gurus to help me out here!
 
Dom Lassy
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't you make a validator rule for a positive number and apply that rule as well as your regex mask?
 
Amieya Prabhaker
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please give an example how I can create a validator rule.

Greatly appreciate the input as I'm still learning the nuts and bolts of this. Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic