Forum: Ruby on Rails regex help

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.
99c89698aa4661ec1750c0fb9b798eab?d=identicon&s=25 Nicholas P. Mueller (Guest)
on 2006-06-10 02:08
(Received via mailing list)
I am trying to write a model validates_format_of that will accept a
field containing only certain characters.  I want the field to only
allow the following characters:

a-z, A-Z, 0-9 and the '_', '@', '.' and '-' characters.

I have hunted around a bit and came up with this:

validates_format_of :password, :with => /^([a-zA-Z0-9.\-_@])+
$/, :message => "illegal."

Is that correct?  I tested it a bunch, but I want to ask the
community to be sure.

Thanks,

Nicholas P. Mueller
2c3e9116fabc3e9f09927d1ffa8bf9e3?d=identicon&s=25 Wuher (Guest)
on 2006-06-10 02:18
(Received via mailing list)
I'm hardly an expert, but it looks good to me.  I like to test my regex
using
this website:  http://www.cuneytyilmaz.com/prog/jrx/  Just paste in your
regex without the leading and trailing / marks, and then you can test
input
using the bottom box.  It's fun =D

HTH, Ryan
--
View this message in context:
http://www.nabble.com/regex-help-t1764703.html#a4803438
Sent from the RubyOnRails Users forum at Nabble.com.
6076c22b65b36f5d75c30bdcfb2fda85?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-06-10 02:36
(Received via mailing list)
On Jun 9, 2006, at 5:04 PM, Nicholas P. Mueller wrote:

>
> Is that correct?  I tested it a bunch, but I want to ask the
> community to be sure.
>
> Thanks,
>
> Nicholas P. Mueller
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails


	I think that looks good for what you want. You can shorten it a bit
if you like though ;)

/^([\w.\-_@])+$/

-Ezra
This topic is locked and can not be replied to.