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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validation: using regular expressions" Watch "Validation: using regular expressions" New topic
Author

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 xxx.xxx (for example javaranch.com ).
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.

Update:
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:
^[a-zA-Z0-9]*[\.][a-zA-Z]{2,3}$

This covers the normal domains:
javaranch.com
javaranch.us
siTE123.Xxx

What also need to have is that it will cover the following:
saloon.javaranch.com
web-site.subdom.com

I think I can use the following for the first one:
^[a-zA-Z0-9]*[\.][a-zA-Z]{2,3}[\.][a-zA-Z]{2,3}$

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 xxx.xxx 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:
^[a-zA-Z0-9\-\.]*[\.][a-zA-Z]{2,3}$

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.
 
Don't get me started about those stupid light bulbs.
 
subject: Validation: using regular expressions