I am using following to validate the contact name like :
validates_format_of :merchant_contact_firstname, :with => /^([a-zA-Z
]+)$/, :message=>‘First name is not valid.’
But it gives error even if it is left blank. Acually, it is optional but
if it is present then it can have only alphabets. How can I validate
both presence and format separately in model?
validates_format_of :merchant_contact_firstname, :if => Proc.new {|c|
not c.merchant_contact_firstname.blank?}, :with => /^([a-zA-Z]+)$/,
:message=>‘First name is not valid.’
Meaning that when the merchant_contact_firstname is not blank it gets
evaluated with the regex.