• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Validation: using regular expressions

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic