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 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
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 -- Ludvig Omholt Sektionen för IT och media Stockholms universitet _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Thanks for the reply Ludde. The regexp works now on english characters but won''t accept german characters (äöüß). Any ideas? Does /^\w+$/ work on all swedish characters? Regards Adam 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 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Tue, Nov 29, 2005 at 04:44:02PM +0100, Adam Groves wrote:> Thanks for the reply Ludde. The regexp works now on english characters but > won''t accept german characters (äöüß). Any ideas? Does /^\w+$/ work on all > swedish characters?Actually it doesn''t match swedish characters when I try it in irb. I would probably solve the problem by using a bracket expression listing all acceptable characters: /^[A-Za-zÄÖÜäöüß]+$/ /ludde> Regards > > Adam > > 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> _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-- Ludvig Omholt Sektionen för IT och media Stockholms universitet _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails