Forum: Ruby on Rails validates_format_of

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eec43f946d65be32e6b9fd2b3a1582a5?d=identicon&s=25 adam.groves (Guest)
on 2005-11-29 13:31
(Received via mailing list)
Hi there,

I'm trying to validate a field in my form to make sure that it is a
single
word (i.e. no spaces). This word may however contain german characters.

I have in my model:

validates_format_of :name,
    :with => %r{\w+},
    :message => "cannot contain special characters or spaces"

but this lets anything through. I freely admit that I'm a reexp
beginner,
infact 'beginnner' may be self-flattery.

Would appreciate any advice/help
3ea73fa7e6073a83296dcdd1dbedd445?d=identicon&s=25 ludvig.omholt (Guest)
on 2005-11-29 14:36
(Received via mailing list)
On Tue, Nov 29, 2005 at 01:30:08PM +0100, Adam Groves wrote:
> Hi there,
>
> I'm trying to validate a field in my form to make sure that it is a single
> word (i.e. no spaces). This word may however contain german characters.
>
> I have in my model:
>
> validates_format_of :name,
>     :with => %r{\w+},
>     :message => "cannot contain special characters or spaces"

      :with => /^\w+$/,

Will probably do what you want. ^ matches the beginning of the string
and $ matches the end.

/ludde
This topic is locked and can not be replied to.