Skip to content

Instantly share code, notes, and snippets.

@khoand0000
Created September 11, 2014 15:18
Show Gist options
  • Save khoand0000/c55f267460d0e33fd6c2 to your computer and use it in GitHub Desktop.
Save khoand0000/c55f267460d0e33fd6c2 to your computer and use it in GitHub Desktop.
http://phpsnips.com/610/Format-Social-Security-Number#.VBG8-fmSySr Takes a string of numbers and formats it into a Social Security number format. Example: formatSSN('123456789'); //returns "123-45-6789"
<?php
// Format a Social Security Number.
function formatSSN($ssn)
{
return preg_replace("/^(\d{3})(\d{2})(\d{4})$/", "$1-$2-$3", $ssn);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment