That doesn't preserve the format, though.

Variation on the prior theme, allows any non-digit spacer, and ensures the
length of the input matches - no excess before or after.

> rx = /^\d{2}(.?)\d{2}\1\d{2}$/
=> /^\d{2}(.?)\d{2}\1\d{2}$/
> #test1: all should pass
* ['234567', '23 45 67', '23a45a67'].all?{|s| s=~rx}
=> true
> #test2; none should pass
* ['23 4567', '23-45 67', '23a45a67a9'].any?{|s| s=~rx}
=> false



James Mason
Systems Administrator/Safety & Environmental Director
Yamato Engine Specialists
360-306-5017


On Wed, Aug 27, 2008 at 3:58 PM, osagie uwaifo <[EMAIL PROTECTED]>wrote:

> I dont know about which is better. You can try this. It would only take out
> the numbers and leave out any other characters
>
>    self.credit_card = credit_card.gsub(/[^0-9]/, '')
>
> Thanks,
> Osagie Uwaifo
>
>
> On Wed, Aug 27, 2008 at 1:09 AM, miga <[EMAIL PROTECTED]> wrote:
>
>>
>>
>>
>> On Aug 26, 11:35 pm, "raul parolari" <[EMAIL PROTECTED]> wrote:
>> > > xx?xx?xx where x is a digit and ? may be either nothing, blank, or
>> dash,
>> >
>> > but no mix between them.
>> >
>> > So the '?'  in a particular string has the same value. Then, a simpler
>> > regexp is:
>> >
>> > re = /\A  \d{2}([- ]?)  \d{2}\1  \d{2}  \Z/x
>> I did not know this particularity of '?'. Thank you very much.
>>
>>
>>
>>
>
> >
>



Confidentiality Notice:
The documents accompanying this electronic transmission may contain 
confidential information. The information is intended only for the use of the 
individual(s) or entity named above. If you are not the intended recipient, you 
are notified that any disclosure, copying, distribution or taking of any action 
in reliance on the contents of this electronic information is not permissible. 
If you have received this electronic document in error, please immediately 
notify us by telephone at (360)733-1916.
Thank you.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to