Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

matt http://www.elleandergrey.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

hide credit card numbers

// hide all digits of a credit card number except the last 4. eg<br/>
// cc = "12345678901123456"
// hide_card_number(cc)
// [ "************3456" ]

  def hide_card_number(card_number)
    size = card_number.to_s.size - 1
    cc = "" 
    i = 0
    0.upto(size) do 
      if( i > size - 4 )
      else
        cc += "*" 
      end
      i += 1
    end
    cc = cc + card_number[size-3, size].to_s
    return cc 
  end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS