Friday, February 18, 2011

Re: [Rails] validates_format_of :phone with => /^\([0-9]{3}\)[-. ]?[0-9]{3}[-. ]?[0-9]{4}|^[0-9]{3}[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/

On 18 February 2011 05:24, Victor S <victor.stan@gmail.com> wrote:
> Why doesn't this phone validation work?
> validates_format_of :phone, :with => /^\([0-9]{3}\)[-. ]?[0-9]{3}[-.
> ]?[0-9]{4}|^[0-9]{3}[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/,
>                       :message => "is not a phone number"
> tested with (123) 456 7890
> testing it here does work: http://www.rubular.com/ but in a rails app, it
> fails validation except for 1234567890

In these situations I dramatically simplify until I get an expression
that does what I expect then build it back up to find the cause of the
failure. Since you seem to suggest that it is not working when
parentheses are included I would start with an expression that allows
(n) and work up from there.

Remember you can run it in the rails console so you do not need to
keep editing the app.

Colin

--
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate