Mask All But Last 4 Digits
Join the DZone community and get the full member experience.Join For Free
If you need to mask all but the last 4 digits of a nubmer - like a credit card number - this helper works nicely. Just pass it a number or string.
def mask_number(number) number.to_s.size < 5 ? number.to_s : (('*' * number.to_s[0..-5].length) + number.to_s[-4..-1]) end
Opinions expressed by DZone contributors are their own.