Thank you Reinaldo,

I modified the callbacks with
self.credit_card.gsub!(/[\s\-]/, '') but the result  is the same, the field
is inserted and updated without normalize.
 Is there any log where it shows if the callbacks are executed...?
thanks

2009/10/25 Reinaldo Silva <[email protected]>

> hi,
>
> First, you could use a simplified pattern as:
>
>
> /\d{4}[\- ]?\d{4}[\- ]?\d{4}[\- ]?\d{4}/
>
> Certainly this pattern accept expressions as:
>
> 9999-9999 9999 9999, and
> 9999 9999-99999999
>
> and similars, but you will normalize it anyway.
>
> And also accepts the standard expressions:
>
> 9999999999999999
> 9999-9999-9999-9999
> 9999 9999 9999 9999
>
> About the normalization, do:
>
> self.credit_card.gsub!(/[\s\-]/, '')
>
>
>
>
> On Sat, 24 Oct 2009 00:43:14 -0430, Luis Yanson <[email protected]> wrote:
>
>  Please, Can some body guide me with this issue..?
>>
>> I can't normalize the credit_card number,
>> my model code is:
>>
>> validates_format_of :credit_card,
>>     :with => /(\d{16})|(\d{4})[' '](\d{4})[' '](\d{4})['
>> '](\d{4})|(\d{4})[-](\d{4})[-](\d{4})[-](\d{4})/,
>>     :on=> :create,
>>     :message=>"Invalid number format"
>>
>>  #callback before update
>>   before_save:normalize_number
>>  private
>>  def normalize_number
>>         self.credit_card.delete' '
>>         self.credit_card.delete'-'
>>
>>  end
>>
>> Thanks in advance
>>
>> Luis
>>
>> >>
>>
>
> --
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "ruby-on-rails-programming-with-passion" group.
To unsubscribe from this group, send email to
ruby-on-rails-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/ruby-on-rails-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to