Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: masking SSN to last four

by davido (Cardinal)
on Aug 09, 2019 at 02:18 UTC ( [id://11104209]=note: print w/replies, xml ) Need Help??


in reply to masking SSN to last four

sub ss_last_4 { my $n = shift; $n =~ tr/0-9//cd; # We can only work with numeric digits. # There are some basic constraints we can assure are met. die "$n cannot be a social security number.\n" if 9 != length($n) || $n =~ m/(^0{3})|(^\d{3}0{2})|(0{4}$)/ # A grouping of +zeros represents a fictitious SS number. || substr($n,0,3) == 666 # Prefixes that +== 666, or are >= 900 and <= 999 are reserved. || substr($n,0,3) >= 900; # Still alive, return the last four. return substr($n,-4,4); }

Just today a website rejected my phone number because I entered it without hyphens. Amazing how something that is really only a formatting convention gets baked into validation. Ok, for socials hyphens are supposed to be a requirement, but how many times have you visited websites where the hyphen handling is wonky? IMO it's easier to filter them out on input, and re-apply them on output.

Don't be tempted to use SSN::Validate (which could easily return the last four for you); in 2011 the US government made changes to how the first three digits are allocated, and the changes broke assumptions made in that module.


Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11104209]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-20 06:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found