i use this to validate a username on signup validates_format_of :name, :with => /[a-zA-Z]+/, :on => :create i am certainly no regular expression expert. i intended that no one is able to sign up with spaces or special characters. unfortunately it seems like some people are able to sign up with "firstname lastname" or with "http://feedication.com/username" which is not that optimal "firstname lastname" works but doesnt look pretty and the thing with the whole adress maybe an issue of unoptimal signup form which may be a bit unclear about what to fill in, but even if it would be clear, it shouldn''t be possible ;) any suggestions what may be wrong with the reg-exp? cheers, Thomas
Your regex matches because *some part* of what the user typed is 1 or more letters. I think you want to anchor it with \A and \Z (That is, /\A[a-zA-Z]+\Z/) On 5/26/05, Thomas Schranz <thomas.schranz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> i use this to validate a username on signup > > validates_format_of :name, :with => /[a-zA-Z]+/, :on => :create > > i am certainly no regular expression expert. > i intended that no one is able to sign up with spaces or special > characters. > > unfortunately it seems like some people are able to sign up with > "firstname lastname" or with "http://feedication.com/username" which > is not that optimal > > "firstname lastname" works but doesnt look pretty > and the thing with the whole adress maybe an issue of unoptimal > signup form which may be a bit unclear about what to fill in, but > even if it would be clear, it shouldn''t be possible ;) > > any suggestions what may be wrong with the reg-exp? > > cheers, > Thomas > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
> On 5/26/05, Thomas Schranz <thomas.schranz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > i use this to validate a username on signup > > > > validates_format_of :name, :with => /[a-zA-Z]+/, :on => :create > > > > i am certainly no regular expression expert. > > i intended that no one is able to sign up with spaces or special > > characters.On Thu, May 26, 2005, Michael Campbell wrote:> Your regex matches because *some part* of what the user typed is 1 or > more letters. > > I think you want to anchor it with \A and \Z (That is, /\A[a-zA-Z]+\Z/)What do \A and \Z do? I''ve never seen those before. I use ^ for beginning of line and $ for end of line. To accomplish this, I''d use /^\w+$/, allowing underscore, digits, and all lower- and upper-case letters. You could just as easily do /^[a-z]+$/i, for letters only, or /^[:alpha:]+$/ for the same. Ben
thanks a lot Michael! i think ive got a bit closer to understand reg exps...i thought my expression would check everything but yeah obviously it was just checking if 1 or more characters are letters and not if all of them are :D if i want to add numbers too i could do /\A[a-zA-Z0-9]+\Z/ right? thanks a lot On 5/27/05, Michael Campbell <michael.campbell-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Your regex matches because *some part* of what the user typed is 1 or > more letters. > > I think you want to anchor it with \A and \Z (That is, /\A[a-zA-Z]+\Z/) > > > > On 5/26/05, Thomas Schranz <thomas.schranz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > i use this to validate a username on signup > > > > validates_format_of :name, :with => /[a-zA-Z]+/, :on => :create > > > > i am certainly no regular expression expert. > > i intended that no one is able to sign up with spaces or special > > characters. > > > > unfortunately it seems like some people are able to sign up with > > "firstname lastname" or with "http://feedication.com/username" which > > is not that optimal > > > > "firstname lastname" works but doesnt look pretty > > and the thing with the whole adress maybe an issue of unoptimal > > signup form which may be a bit unclear about what to fill in, but > > even if it would be clear, it shouldn''t be possible ;) > > > > any suggestions what may be wrong with the reg-exp? > > > > cheers, > > Thomas > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Friday 27 May 2005 07:09, Thomas Schranz wrote:> thanks a lot Michael! > > i think ive got a bit closer to understand reg exps...i thought my > expression would check everything but yeah obviously it was just > checking if 1 or more characters are letters and not if all of them > are :D > > if i want to add numbers too i could do > > /\A[a-zA-Z0-9]+\Z/ > > right?You can also do /^\w+$/ \w is a pseudo-class that is a shorthand for [a-zA-Z0-9_], it''s exactly what normal login names are made of. -- sdmitry -=- Dmitry V. Sabanin http://sabanin.ru