Nanyang Zhan wrote:
I created a form to edit user's information.
In the form there are fields that are optional to fill, like phone
I use some Rails' validations to validate the form, intending to filter
any bad information when user DO enter something. One of these
now the problem is:
when the phone number field is left blank, which is acceptable by me,
Rails jumps out and says "Phone is not a number".
So, how to validate not blank attributes only?
You can use the validate method within the user model like is shown at the top of http://api.rubyonrails.org/classes/ActiveRecord/Validations.html
You can then use a regular expression or manually check to see if the phone number meets your requirements.