On Tue, Jan 17, 2012 at 3:20 AM, Kapil Kaligotla wrote:

validates :first_name,      :format => {:with => /^[a-zA-Z.\s]*$/
i}, :length => {:minimum => 1, :maximum => 25}, :presence => true
Your format regex will pass an empty string (""), or a string of nothing
but space characters, so that's pointless. Alternatively, if you check
for at least one valid word character, then the name must be present
and must be at least 1 character long. (I'm not sure why you have
either the \s or . in there.)

If you've specified a minimum length of 1, then the :presence check
is also pointless, isn't it?

You could condense this whole thing into one regular expression,
which would likely give you only one error message :-)

e.g.   /\A\s*[a-zA-Z]{1,25}\s*\Z/

Aside: You might also want to reconsider your requirements -- for
example "D'Arcy" is a legitimate first name :-)

Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Discussion Posts


Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 6 of 6 | next ›
Discussion Overview
grouprubyonrails-talk @
postedJan 11, '12 at 1:28p
activeJan 17, '12 at 6:47p



site design / logo © 2021 Grokbase