Re: Regular expression: How do I allow forward slashes?

Alan
Sat, 19 Dec 2009 10:12:21 -0000

Use Ruby''s other regexp syntax:

  %r{pattern}

To continue your example below:

  validates_format_of :url, :with => %r{^[-\w_./]+$}

AlwaysCharging wrote:
> In my app, I allow users to submit urls.  They (of course) need the
> ability to submit urls with a forward slash, "/", but whats the
> regular expression to allow them to do that?
>
> I currently use:
>
> validates_format_of :url, :with => /^[-\w\_.]+$/i