Hi everyone, what’s the syntex to check if a field is a number. If my
filed is called “phonefiled”.
thanks for the help in advance.
Hi everyone, what’s the syntex to check if a field is a number. If my
filed is called “phonefiled”.
thanks for the help in advance.
wings wrote:
Hi everyone, what’s the syntex to check if a field is
a number. If my filed is called “phonefiled”.
validates_numericality_of :phonefiled
There are options you should check out at api.rubyonrails.org
hth,
Bill
Hi Guys,
validates_numericality_of :phonefiled
Well, phone “numbers” are almost never numbers. You might have “(02)
9876 5432” or “+61 2 9876 5432”. Best to validate against a regexp,
e.g.:
phone_number =~ /[0-9() +]+/
There are options you should check out at api.rubyonrails.org
Yes, their examples even have phone number validation:
http://api.rubyonrails.org/classes/ActiveRecord/Validations.html
Regards,
Dave
+1 for Regex.
You never know when a user will input any of these valid phone numbers
versions
(404) 555 1212
404 555-1212
4045551212
etc…
RSL
Thanks for the help guys!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs