Vvan
> self.credit_card = credit_card.gsub(/[^0-9]/, "") if ..
In the exercise, the format had to be "4 *sets of 4 digits separated by
dashes or blanks*". The expression you wrote would clean up things like:
"01234 bonjour 5 madame! 67 December 8 9012 3 4 5
..".gsub(/[^0-9]/, "")
=> "0123456789012345"
However, it is a first approximation, and I would not obsess on this now, if
you want to catch up with the course. Regular expressions are a (splendid)
language apart, that you can pick up later (spending a couple of weeks of
serious work on them).
Raul
On Mon, Dec 8, 2008 at 4:23 AM, Volkan Van <[EMAIL PROTECTED]> wrote:
> Raul,
> I took the validation code for the credit card out of
> before_validation_on_create and wrote a separate method for it. and just
> called it with
>
> before_validation :normalize_cc_number
>
> This is my custom method:
>
> def normalize_cc_number
> self.credit_card = credit_card.gsub(/[^0-9]/, "") if
> attribute_present?("credit_card")
> end
>
> That did the trick
>
> Thanks heaps for the respond...
>
> On 08/12/2008, at 8:45 AM, raul parolari wrote:
>
>
> Vvan,
>
> If you are using a regexp that was used to process 'digits + spaces..',
> it is not surprising that if fails for a string with 'alpha chars +
> spaces'.
>
> However, as we are weak in divine powers, it would help if you showed the
> code that you are using, rather than saying "*it is similar as for the
> credit card*"..:-)
>
> Raul
>
>
> On Sat, Dec 6, 2008 at 12:19 AM, vvan <[EMAIL PROTECTED]> wrote:
>
>>
>> Hi all,
>>
>> I have been searching in the previous posts but could not find an
>> answer to my problem.
>>
>> During the lab exercises for this chapter we wrote a
>> before_validation_on_create method and stripped everything from the
>> 'name' attribute but left alphabets...
>> I added another line of code to that for the credit card format which
>> strips everything but numbers.
>>
>> Credit card part works perfectly fine but now the name part of it
>> doesn't work. Meaning if the name entered is 'Volkan Van' it gets
>> saved as 'Volkan Van' instead of 'VolkanVan'
>>
>> Could this be because there can be code only belonging to one
>> attribute or am I completely of track?
>>
>>
>> Thank in Advance for any help
>>
>> >>
>>
>
>
--~--~---------~--~----~------------~-------~--~----~
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
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/ruby-on-rails-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---