aspose file tools*
The moose likes Struts and the fly likes Validation: using regular expressions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validation: using regular expressions" Watch "Validation: using regular expressions" New topic

Validation: using regular expressions

Ergin Er
Ranch Hand

Joined: Sep 06, 2005
Posts: 60
Hi all,

I'm trying to get a field "name", that should exist out of a domain name with at least one dot, validated.

This code from validation.xml should check the field on its (max)length, is "emptyness" and if it's correctly written. I tried to cover the needed spec by the regular expression (my first attempt). This expression should point out that the inserted string has be at least (for example ).
When testing this I can insert wzzz without a dot or bla.yaba.daba.doodle without problems. Is my rule not valid or may also have other validation configuration probs?
I did enable validator plugin in my struts-config and the property "name" is also correctly spelled in the form bean and the jsp. Any help would be appreciated.

The validation was not properly configured. Needed to extend the Form with ValidatorForm. Now I can validate. (But need to tweak the regular expression)
[ September 15, 2005: Message edited by: Ergin Er ]
Ergin Er
Ranch Hand

Joined: Sep 06, 2005
Posts: 60
I made some grounds on my regular expression. Here is what I've got so far:

This covers the normal domains:

What also need to have is that it will cover the following:

I think I can use the following for the first one:

The question is:
I can't add 2 mask values formset in the validation.xml. Is there and "or" possibility so that I can insert the 2nd expression in the same mask. Or better yet:
Can I define a mask in such a way that it looks at the sting for at least a combo and that it may contain "-"?
Ergin Er
Ranch Hand

Joined: Sep 06, 2005
Posts: 60
Hi all,

here is a new update on my progress:

With this I can pretty much cover all the possible domains. The only problem with this expression is that it also allows ".." or "--" being put in domains.
So somehow I have to exclude these possibilities within this expression.
I agree. Here's the link:
subject: Validation: using regular expressions