On Tue, Jan 17, 2012 at 3:20 AM, Kapil Kaligotla
<[email protected]> 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 :-)
HTH,
--
Hassan Schroeder ------------------------ [email protected]
http://about.me/hassanschroeder
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.