From: dblack@... Date: 2006-09-03T21:22:25+09:00 Subject: Re: RegExp issues.... Hi -- On Sat, 2 Sep 2006, Eric Hodel wrote: > > On Sep 1, 2006, at 6:57 PM, Ben V. wrote: > >> 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. > > That regexp doesn't match lowercase characters. > > input =~ /\A[\w-]+\Z/ is probably better. \Z will allow a final newline character, though, so you'd probably want to use \z. David -- David A. Black | dblack@wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org