GeeCON Prague 2014*
The moose likes Struts and the fly likes Mask Validator Does not recognize valid regex expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Mask Validator Does not recognize valid regex expression" Watch "Mask Validator Does not recognize valid regex expression" New topic
Author

Mask Validator Does not recognize valid regex expression

Samson Mlati
Ranch Hand

Joined: Feb 23, 2009
Posts: 41

Hi guys,

I'm working with struts 1 and have a problem with the mask validator. The validator rejects valid values and it beats me where I'm going wrong. Check out the regex and validation mask below.

validation.xml

<global>

<constant>
<constant-name>validationMask</constant-name>
<constant-value>^[A-Z-[^W]][A-Z-[^TAC]]\d\d\d\d\d$</constant-value>
</constant>

</global>

<field property="assetId" depends="required,mask">
<arg0 key="label.receive.assetID" />
<msg name="mask" key="receiveForm.asset.maskmsg"/>
<var>
<var-name>mask</var-name>
<var-value>${validationMast}</var-value>
</var>
</field>

The regular expression should and does allow a custom serial number of this format: WA00000 or WC0000 or WT00000...thats outside of struts. The result when i run my form is that the field is always invalid when i enter valid values.... please help. Does the validator not recognize some regular expressions??

Thanks,


Mlati.


Best,
Mlati
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Is the var-value a typo?

Please use code tags.

I'm not really sure that's a valid regex, either. I just tried online with several different regex testers and none of them do what I think you're asking it to. Is the regex supposed to accept A-Z except W, followed by A-Z except TAC, and 5 digits?

http://regex.powertoy.org/
http://myregexp.com/
Samson Mlati
Ranch Hand

Joined: Feb 23, 2009
Posts: 41

David Newton wrote:Is the var-value a typo?

Please use code tags.

I'm not really sure that's a valid regex, either. I just tried online with several different regex testers and none of them do what I think you're asking it to. Is the regex supposed to accept A-Z except W, followed by A-Z except TAC, and 5 digits?

http://regex.powertoy.org/
http://myregexp.com/


Hi David,

It's a valid one...i've tested it using two validator applications and it works fine, just not with struts validator. The [A-Z-[^W]] means accept only the letter W, you can read that A-Z Minus NOT W. The rule accepts serial numbers of the form WA00000 or WC00000 or WA0000, that's what I'm trying to achieve.

Mlati
Samson Mlati
Ranch Hand

Joined: Feb 23, 2009
Posts: 41

Samson Mlati wrote:
David Newton wrote:Is the var-value a typo?

Please use code tags.

I'm not really sure that's a valid regex, either. I just tried online with several different regex testers and none of them do what I think you're asking it to. Is the regex supposed to accept A-Z except W, followed by A-Z except TAC, and 5 digits?

http://regex.powertoy.org/
http://myregexp.com/


Hi David,

It's a valid one...i've tested it using two validator applications and it works fine, just not with struts validator. The [A-Z-[^W]] means accept only the letter W, you can read that A-Z Minus NOT W. The rule accepts serial numbers of the form WA00000 or WC00000 or WA0000, that's what I'm trying to achieve.


Thanks for the tip on online validators. When I check the expression using those it fails, i had downloaded two regex builders and they all agreed that the expression is valid..not the online ones though. Long story short if i avoid the MINUS and negation the expression works with the on line validators, i'm sure the struts validator wont have a prob either. Here is the new expression ^[W][ATC]\d\d\d\d\d$

Thanks....

Mlati

Mlati
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Then your regexes make no sense to me. If you *just* want W, then just put a W. If you want TAC, then just use TAC.

W[TAC]\d\d\d\d\d

In any case, you still need to use ORO syntax, which I don't remember. Neither of the validators I linked to thought your regex was valid, and it's syntax I've never seen before.
Samson Mlati
Ranch Hand

Joined: Feb 23, 2009
Posts: 41

David Newton wrote:Then your regexes make no sense to me. If you *just* want W, then just put a W. If you want TAC, then just use TAC.

W[TAC]\d\d\d\d\d

In any case, you still need to use ORO syntax, which I don't remember. Neither of the validators I linked to thought your regex was valid, and it's syntax I've never seen before.


Yea..doesn't make any sense. Already figured out above. Thanks
Samson Mlati
Ranch Hand

Joined: Feb 23, 2009
Posts: 41

Samson Mlati wrote:
Samson Mlati wrote:
David Newton wrote:Is the var-value a typo?

Please use code tags.

I'm not really sure that's a valid regex, either. I just tried online with several different regex testers and none of them do what I think you're asking it to. Is the regex supposed to accept A-Z except W, followed by A-Z except TAC, and 5 digits?

http://regex.powertoy.org/
http://myregexp.com/


Hi David,

It's a valid one...i've tested it using two validator applications and it works fine, just not with struts validator. The [A-Z-[^W]] means accept only the letter W, you can read that A-Z Minus NOT W. The rule accepts serial numbers of the form WA00000 or WC00000 or WA0000, that's what I'm trying to achieve.



Hey...

I've actually tested <tr>
<td><bean:message key="label.issue.date" /></td>
<td><html:text property="issueDate" size="25" maxlength="8" onfocus="this.select();" /></td>
</tr>
<tr>
<td><bean:message key="label.issue.location" /></td>
<td><html:text property="location" size="25" maxlength="8" onfocus="this.select();" /></td>
</tr>
<tr>

</tr>

Thanks for the tip on online validators. When I check the expression using those it fails, i had downloaded two regex builders and they all agreed that the expression is valid..not the online ones though. Long story short if i avoid the MINUS and negation the expression works with the on line validators, i'm sure the struts validator wont have a prob either. Here is the new expression ^[W][ATC]\d\d\d\d\d$

Thanks....

Mlati

Mlati




Hey I've tested the new regex on struts and it still won't validate.. any idea why? Does the validator not recognize some expressions?? This beats me, I have ^[W][ATC]\d\d\d\d\d$
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Post the validation config again. You never answered whether or not that was a typo in the original one (or if you did answer, I missed it). The expression is correct and verified using the ORO demo page, so something else is wrong.
Samson Mlati
Ranch Hand

Joined: Feb 23, 2009
Posts: 41

David Newton wrote:Post the validation config again. You never answered whether or not that was a typo in the original one (or if you did answer, I missed it). The expression is correct and verified using the ORO demo page, so something else is wrong.


I answered you, it was not a typo. Its a valid expression. Here is my config though. Thanks

<form name="MyForm">
<field property="assetId" depends="required,mask">
<arg0 key="label.receive.assetID" />
<var-name>mask</var-name>
<var-value>^[W][TAC]\d\d\d\d\d$</var-value>
<msg name="mask" key="receiveForm.asset.maskmsg"/>
</field>
</form>
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

No, you didn't--I was asking about the var-value, as stated in my original reply:I was asking if that was a typo.

Now you're doing it differently, so it doesn't matter, which is why I wanted the post of your current config.

I don't see anything obviously wrong. Do you have other working validations?

You don't need the brackets around the W, by the way, although that won't cause it not to work.
Samson Mlati
Ranch Hand

Joined: Feb 23, 2009
Posts: 41

David Newton wrote:No, you didn't--I was asking about the var-value, as stated in my original reply:I was asking if that was a typo.

Now you're doing it differently, so it doesn't matter, which is why I wanted the post of your current config.

I don't see anything obviously wrong. Do you have other working validations?

You don't need the brackets around the W, by the way, although that won't cause it not to work.



Yes other validations work. Just not the mask, i've tried a simpler mask like [A-Z]* and that validates alright.. do you suppose its a bit to complex for the validator?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

No, the regex works fine on the ORO demo page. I suppose you could try escaping the backslash in case there's something funky going on with Java strings, but that seems very unlikely. Or including a "mask" msg in case that's required, but I didn't think it was.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mask Validator Does not recognize valid regex expression