Ugo Cei wrote:
I'm in need of a simple URL validator for CForms. It should test
whether a string value represents a well-formed URL and if it doesn't,
prepend "http://"; and try again.
I think this would nicely cover the use case where you need to specify
a website address in a form but don't want to force users to specify
the protocol.
Has anybody come up with something similar before?
Also, I would like the field value to be a well-formed URL in any
case, so it should always contain a protocol part. Is it allowed for a
validator to change the value of its widget?
Hmm... not good as the validation expects the form to be in a stable
state throughout the whole validation phase. We should even add checks
to ensure widgets don't change within the validation phase :-)
Would it be better instead to define a new "url" datatype and
corresponding convertor? It looks cleaner, but it also seems overkill
to define a validator, a datatype and a convertor (plus factory
classes) just to cover this simple use case.
WDYT?
What about a simple value-changed listener that adds the protocol when
it's not there? It will be called before the validator, which can then
check the absolute URL with its protocol.
Sylvain
--
Sylvain WallezAnyware Technologies
http://apache.org/~sylvainhttp://anyware-tech.com
Apache Software Foundation Member Research & Technology Director