From: Gareth Adams Date: 2006-09-03T21:12:32+09:00 Subject: Re: RegExp issues.... Ben V. gmail.com> writes: > > I am trying to validate user input so it contains only letters, numbers, > underscores and dashes. I am using this regexp:/[A-Z0-9_-]/. However, > when I type in 'hello' in the field, it says that it doesn't match the > regexp, yet I'm sure that reg exp works for letters, numbers, and > underscores only. What am I doing wrong? Thanks for your help and time. > No one else seems to have mentioned that that regex will match all strings /conatining/ a letter, digit hyphen or underscore: irb(main):001:0> /[A-Z0-9_-]/ =~ "贈$%^" => nil irb(main):002:0> /[A-Z0-9_-]/ =~ "贈$0%^" => 2 You probably want something like /^[\w-]+$/ Gareth