Struts validator regular expression for URL?

J

Joe Bloggs

Hi,

can someone kindly suggest a regular expression that I can use with Struts
validator?

I have a regular expression like this:

validation.xml
=============

[snip]
<constant>
<constant-name>url</constant-name>
<constant-value>^(http:\/\/)?([\w-]+\.)+[\w-]+(/[\w-
../]*)?</constant-value>
</constant>

[snip]

but when Struts generates the javascript using this mask, it complains about
some "Object required" error. I have isolated it down to the culprit
(http:\/\/)?
it seems that the javascript generated does not treat // characters kindly.
If I remove this bit, the regular expression works.

So am I forced to only check for an URL string without the "http:// "
prefix?

Thanks
 
R

Roedy Green

<constant-value>^(http:\/\/)?([\w-]+\.)+[\w-]+(/[\w-
./]*)?</constant-value>

You have at least two flavours of quoting going on. This is the bane
of Regex. Regex and XML. For all I know there may be another level
if this stuff in turned into Java source.

I would suspect that < > and / all need special handling in XML.
For the list of chars that need to be quoted in Regex, see
http://mindprod.com/jgloss/regex.html


This is one of the reasons I prefer binary formats. You don't get
mired in layers of quoting. The quoting undoes the supposed simplicity
of the text format.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top