Making Validations Optional

Hello,

I am working with URL validations. I want this validation to be
optional if the data exists in the form submission. I have tried
several things.

validates_format_of :website,
:if => params[:organization][:website],
:with =>
/((http|https)://)?[a-z0-9]+([-.]{1}[a-z0-9]+).[a-z]
{2,5}(([0-9]{1,5})?/.
)?/,
:message => “Please enter a valid url”

Of course the challenge is in the :if statement

I won’t bother you guys with all of my experiments, but I have tried
using :website, :website.length > 0, params[:organization][:website]
and creating a method in my organization class. None of these have
worked. What am I missing?

Thanks!

You cannot access params in model.

On 8/7/07, Mindtonic [email protected] wrote:

{2,5}(([0-9]{1,5})?/.*)?/,


Cheers!

Ahhh… so I was barking up the wrong proverbial tree.

The solution to the problem lay in the REGEX code. I simply added a
test for zero or one instance at the end:

/(((http|https)://)?[a-z0-9]+([-.]{1}[a-z0-9]+).[a-z]{2,5}(([0-9]
{1,5})?/.
)?)*/

Thanks.