How can I validate US Social Security Number?












33















Anyone out there know how to improve this function? I'm not worried about shortening the code, I'm sure this could be done with better regex, I am more concerned about correct logic. I have had a terrible time finding documentation for SSN #'s. Most of the rules I use below have come from other programmers who work in the credit industry (no sources cited).




  1. Are there any additional rules that
    you are aware of?

  2. Do you know if any of this is wrong?

  3. Can you site your sources?


Thanks for any insight!



    public static bool isSSN(string ssn)
{
Regex rxBadSSN = new Regex(@"(d)11111111");

//Must be 9 bytes
if(ssn.Trim().Length != 9)
return false;

//Must be numeric
if(!isNumeric(ssn))
return false;

//Must be less than 772999999
if( (Int32)Double.Parse(ssn.Substring(0,3)) > 772 )
{
//Check for Green Card Temp SSN holders
// Could be 900700000
// 900800000
if(ssn.Substring(0,1) != "9")
return false;

if(ssn.Substring(3,1) != "7" && ssn.Substring(3,1) != "8")
return false;
}

//Obviously Fake!
if(ssn == "123456789")
return false;

//Try again!
if(ssn == "123121234")
return false;

//No single group can have all zeros
if(ssn.Substring(0,3) == "000")
return false;
if(ssn.Substring(3,2) == "00")
return false;
if(ssn.Substring(5,4) == "0000")
return false;

//Check to make sure the SSN number is not repeating
if (rxBadSSN.IsMatch(ssn))
return false;

return true;
}









share|improve this question





























    33















    Anyone out there know how to improve this function? I'm not worried about shortening the code, I'm sure this could be done with better regex, I am more concerned about correct logic. I have had a terrible time finding documentation for SSN #'s. Most of the rules I use below have come from other programmers who work in the credit industry (no sources cited).




    1. Are there any additional rules that
      you are aware of?

    2. Do you know if any of this is wrong?

    3. Can you site your sources?


    Thanks for any insight!



        public static bool isSSN(string ssn)
    {
    Regex rxBadSSN = new Regex(@"(d)11111111");

    //Must be 9 bytes
    if(ssn.Trim().Length != 9)
    return false;

    //Must be numeric
    if(!isNumeric(ssn))
    return false;

    //Must be less than 772999999
    if( (Int32)Double.Parse(ssn.Substring(0,3)) > 772 )
    {
    //Check for Green Card Temp SSN holders
    // Could be 900700000
    // 900800000
    if(ssn.Substring(0,1) != "9")
    return false;

    if(ssn.Substring(3,1) != "7" && ssn.Substring(3,1) != "8")
    return false;
    }

    //Obviously Fake!
    if(ssn == "123456789")
    return false;

    //Try again!
    if(ssn == "123121234")
    return false;

    //No single group can have all zeros
    if(ssn.Substring(0,3) == "000")
    return false;
    if(ssn.Substring(3,2) == "00")
    return false;
    if(ssn.Substring(5,4) == "0000")
    return false;

    //Check to make sure the SSN number is not repeating
    if (rxBadSSN.IsMatch(ssn))
    return false;

    return true;
    }









    share|improve this question



























      33












      33








      33


      9






      Anyone out there know how to improve this function? I'm not worried about shortening the code, I'm sure this could be done with better regex, I am more concerned about correct logic. I have had a terrible time finding documentation for SSN #'s. Most of the rules I use below have come from other programmers who work in the credit industry (no sources cited).




      1. Are there any additional rules that
        you are aware of?

      2. Do you know if any of this is wrong?

      3. Can you site your sources?


      Thanks for any insight!



          public static bool isSSN(string ssn)
      {
      Regex rxBadSSN = new Regex(@"(d)11111111");

      //Must be 9 bytes
      if(ssn.Trim().Length != 9)
      return false;

      //Must be numeric
      if(!isNumeric(ssn))
      return false;

      //Must be less than 772999999
      if( (Int32)Double.Parse(ssn.Substring(0,3)) > 772 )
      {
      //Check for Green Card Temp SSN holders
      // Could be 900700000
      // 900800000
      if(ssn.Substring(0,1) != "9")
      return false;

      if(ssn.Substring(3,1) != "7" && ssn.Substring(3,1) != "8")
      return false;
      }

      //Obviously Fake!
      if(ssn == "123456789")
      return false;

      //Try again!
      if(ssn == "123121234")
      return false;

      //No single group can have all zeros
      if(ssn.Substring(0,3) == "000")
      return false;
      if(ssn.Substring(3,2) == "00")
      return false;
      if(ssn.Substring(5,4) == "0000")
      return false;

      //Check to make sure the SSN number is not repeating
      if (rxBadSSN.IsMatch(ssn))
      return false;

      return true;
      }









      share|improve this question
















      Anyone out there know how to improve this function? I'm not worried about shortening the code, I'm sure this could be done with better regex, I am more concerned about correct logic. I have had a terrible time finding documentation for SSN #'s. Most of the rules I use below have come from other programmers who work in the credit industry (no sources cited).




      1. Are there any additional rules that
        you are aware of?

      2. Do you know if any of this is wrong?

      3. Can you site your sources?


      Thanks for any insight!



          public static bool isSSN(string ssn)
      {
      Regex rxBadSSN = new Regex(@"(d)11111111");

      //Must be 9 bytes
      if(ssn.Trim().Length != 9)
      return false;

      //Must be numeric
      if(!isNumeric(ssn))
      return false;

      //Must be less than 772999999
      if( (Int32)Double.Parse(ssn.Substring(0,3)) > 772 )
      {
      //Check for Green Card Temp SSN holders
      // Could be 900700000
      // 900800000
      if(ssn.Substring(0,1) != "9")
      return false;

      if(ssn.Substring(3,1) != "7" && ssn.Substring(3,1) != "8")
      return false;
      }

      //Obviously Fake!
      if(ssn == "123456789")
      return false;

      //Try again!
      if(ssn == "123121234")
      return false;

      //No single group can have all zeros
      if(ssn.Substring(0,3) == "000")
      return false;
      if(ssn.Substring(3,2) == "00")
      return false;
      if(ssn.Substring(5,4) == "0000")
      return false;

      //Check to make sure the SSN number is not repeating
      if (rxBadSSN.IsMatch(ssn))
      return false;

      return true;
      }






      algorithm validation






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 12 '13 at 0:25









      Zyerah

      4,46983663




      4,46983663










      asked Oct 4 '09 at 18:17









      J.HendrixJ.Hendrix

      1,26341523




      1,26341523
























          8 Answers
          8






          active

          oldest

          votes


















          22














          UPDATE



          On June 25, 2011, the SSA changed the SSN assignment process to "SSN randomization".[27] SSN randomization affects the SSN assignment process in the following ways:



          It eliminates the geographical significance of the first three digits of the SSN, previously referred to as the Area Number, by no longer allocating the Area Numbers for assignment to individuals in specific states.
          It eliminates the significance of the highest Group Number and, as a result, the High Group List is frozen in time and can be used for validation of SSNs issued prior to the randomization implementation date.
          Previously unassigned Area Numbers have been introduced for assignment excluding Area Numbers 000, 666 and 900–999.



          New Rules




          • The Social Security number is a nine-digit number in the format "AAA-GG-SSSS". The number is divided into three parts.

          • The middle two digits are the Group Number. The Group Numbers range from 01 to 99.

          • The last four digits are Serial Numbers. They represent a straight numerical sequence of digits from 0001 to 9999 within the group.

          • Some special numbers are never allocated:


            • Numbers with all zeros in any digit group (000-##-####, ###-00-####, ###-##-0000).

            • Numbers with 666 or 900-999 (Individual Taxpayer Identification Number) in the first digit group.



          • SSNs used in advertising have rendered those numbers invalid.


          http://en.wikipedia.org/wiki/Social_Security_number#Structure



          Previous Answer



          Here's the most-complete description of the makeup of an SSN that I have found.






          share|improve this answer





















          • 1





            @user2864740: I have updated the answer to reflect the June 2011 changes.

            – Eric J.
            Jan 26 '15 at 22:12











          • Very interesting.

            – Jeffpowrs
            Oct 22 '15 at 21:37











          • great answer. thank you.

            – catbadger
            Feb 21 '18 at 21:31



















          16














          As of 2011 SSN's are completely randomized (http://www.socialsecurity.gov/employer/randomization.html)



          The only real rules left are:




          • Cannot start with 900-999 (although the Individual Taxpayer Identification Number, which can be used like an SSN by temporary residents and undocumented/DACA/DAPA immigrants in some situations, is in the same format and does start with 9)

          • Cannot start with 666

          • Cannot start with 000

          • Must be 9 numeric digits or 11 with the 2 dashes

          • Cannot be any of the known fakes;


            • "078051120" — Woolworth Wallet Fiasco

            • "219099999" — Was used in an ad by the Social Security Administration



          • Many people exclude repeating an sequential numbers as well, although these are now technically valid, and I feel sorry for the poor schmuck's who gets assigned these.






          share|improve this answer


























          • According to the SSN randomization FAQ, the group (middle 2 digits) or serial number (last 4) also cannot be all 0s.

            – Nick Chammas
            Mar 27 '17 at 20:03



















          14





          +25









          Answer 5 years after initial question due to changes in validation rules by the Social Security Administration. Also there are Specific numbers to invalidate according to this link.



          As per my near-2-year-old answer I also left out isNumeric(ssn) because the field is a numeric and already strips characters before calling the validate function.



          // validate social security number with ssn parameter as string
          function validateSSN(ssn) {
          // find area number (1st 3 digits, no longer actually signifies area)
          var area = parseInt(ssn.substring(0, 3));
          return (
          // 9 characters
          ssn.length === 9 &&
          // no set can start with zero
          ssn.match(/^[1-9][0-9]{2}[1-9][0-9]{1}[1-9][0-9]{3}/) &&
          // disallow Satan's minions from becoming residents of the US
          area !== 666 &&
          // it's over 900
          area < 900 &&
          // fun fact: some idiot boss put his secretary's ssn in wallets
          // he sold, now it "belongs" to 40000 people
          ssn !== '078051120' &&
          // was used in an ad by the Social Security Administration
          ssn !== '219099999'
          );
          }


          According to updated information there are no other checks to perform.






          share|improve this answer































            11














            It's all at socialsecurity.gov: Numbering scheme, allocations, highest numbers updated monthly.






            share|improve this answer



















            • 2





              Yes. In essence, you can't really validate a US social security number. There's no check digit, for instance. About the best you can do is toss stuff that's obviously invalid. Also bear in mind that the possible domain of a US Social Security Number is 1 billion discrete values (0-999999999). Given that there are gaps in the actual domain due to the allocation schema and that there are more than 300m people currently alive in the US, most of whom have social security numbers, nearly a third of the possible domain is taken. Won't be long until we start seeing collisions. That'll be fun.

              – Nicholas Carey
              May 2 '13 at 17:34






            • 1





              This answer now refers to outdated information.

              – user2864740
              Jan 26 '15 at 21:44



















            3














            This is obviously an old post, but I found some ways to shorten it. Also there are a few specific numbers to invalidate according to this link:
            http://www.snopes.com/business/taxes/woolworth.asp



            Here's how I did it. I could have used regexes for repeating numbers, but with specific ones to invalidate we might as well add ones through fives to that list (over 5 will invalidate anyways due to area number validation). I also left out isNumeric(ssn) because the field is a numeric and already strips characters before calling the validate function.



            function validateSSN(ssn) {
            // validate format (no all zeroes, length 9
            if (!ssn.match(/^[1-9][0-9]{2}[1-9][0-9]{1}[1-9][0-9]{3}/)
            || ssn.length!=9) return false;

            // validate area number (1st 3 digits)
            var area=parseInt(ssn.substring(0, 3));
            // standard railroad numbers (pre-1963)
            if (area>649 && !(area>=700 && area<=728)) return false;

            // disallow specific invalid number
            if (ssn=='078051120' || // fun fact: some idiot boss put his
            // secretary's ssn in wallets he sold,
            // now this is 40000 people's ssn
            ssn=='219099999' || // was used in an ad by the Social Security
            // Administration
            ssn=='123456789' || // although valid it's not yet assigned and
            // you're not likely to meet the person who
            // will get it
            ssn=='123121234' || // probably is assigned to someone but more
            // likely to find someone trying to fake a
            // number (next is same)
            ssn=='321214321' || // all the rest are likely potentially
            // valid, but most likely these numbers are
            // abused
            ssn=='111111111' ||
            ssn=='222222222' ||
            ssn=='333333333' ||
            ssn=='444444444' ||
            ssn=='555555555') return false;

            return true;
            }





            share|improve this answer





















            • 2





              These rules are silly. If someone is going to fake '321214321' they might as well fake '102319982' (and yes, I just typed that in randomly). Only the first two specific rules have any substantiated claim AFAIK. In addition the previous excluded ranges are now allowed.

              – user2864740
              Jan 26 '15 at 21:41





















            1














            As of the randomizing of social security numbers post-911, the entries in the 900 series and even 666 are now potentially valid numbers.



            The only certain things at this point in time appear to be:

            the first group of 3 will never be 000

            the middle group pair will never be 00

            and the last four will never be 0000



            You can perform some testing by first testing to ensure that the numeric value of the entry is >= 1010001 [and < 1000000000] (a ssan of 001-01-0001 appears to be the lowest legitimately assigned). Then you can proceed to check for 00 in positions 4 and 5, and 0000 in the last four.






            share|improve this answer





















            • 3





              Please provide an authoratative reference for the first sentence and the following assumptions/rules. It goes against other (previous answers) and government documentation: "Previously unassigned area numbers were introduced for assignment excluding area numbers 000, 666 and 900-999."

              – user2864740
              Jan 26 '15 at 21:39





















            1














            I know this is an old question, but for the sake of others looking for answers, I figured I'd add a quick javascript function for checking that a given SSN is valid.



            function checkSSN() {
            var inputSSN = #YourInput#,
            ssnRegex = new RegExp("^(9[0-9][0-9]|666|000|078051120|219099999|123456789|123121234|321214321)|^([0-8][0-9][0-9]00)|^([0-8][0-9][0-9][0-9][0-9]000)$"),
            repeats = /^(.)1+$/;

            //make sure we have 2 dashes in the input Social Security number
            if( inputSSN.match(/./g).length === 2) {
            //Once we have confirmed that there are the right number of dashes, remove them, and make sure that the resulting string is a number (you may or may not need this logic depending on the format of your input SSN.
            inputSSN = inputSSN.replace(/-/g, "");

            if(!isNaN(inputSSN)) {
            //Test the input SSN against our regex to ensure that it doesn't contain any disqualifying combinations.
            if(!ssnRegex.test(inputSSN)) {
            //Make sure the input SSN isn't just a repeated number
            if(!repeats.test(inputSSN)) {
            //If it lands inside of this, we know it's a valid option for a social security number.
            }
            }
            }
            }


            For the ssnRegex logic:



            The first section handles if the SSN starts with a number 900-999, 666, 000, or one of the known disqualifying SSNs mentioned above.



            ^(9[0-9][0-9]|666|000|078051120|219099999|123456789|123121234|321214321)



            the second section ensures that the 2 digit portion isn't 00



            ^([0-8][0-9][0-9]00)



            The third section ensures that the last portion isn't 0000



            ^([0-8][0-9][0-9][0-9][0-9]0000)



            We additionally check to make sure they have inputted a number, and that they aren't just using a repeated number.






            share|improve this answer































              0














              Here is my PHP version



              /**
              * Validate SSN - must be in format AAA-GG-SSSS or AAAGGSSSS
              *
              * @param $ssn
              * @return bool
              */
              function validate_ssn($ssn) {

              $ssnTrimmed = trim($ssn);

              // Must be in format AAA-GG-SSSS or AAAGGSSSS
              if ( ! preg_match("/^([0-9]{9}|[0-9]{3}-[0-9]{2}-[0-9]{4})$/", $ssnTrimmed)) {
              return false;
              }

              // Split groups into an array
              $ssnFormatted = (strlen($ssnTrimmed) == 9) ? preg_replace("/^([0-9]{3})([0-9]{2})([0-9]{4})$/", "$1-$2-$3", $ssnTrimmed) : $ssnTrimmed;
              $ssn_array = explode('-', $ssnFormatted);

              // number groups must follow these rules:
              // * no single group can have all 0's
              // * first group cannot be 666, 900-999
              // * second group must be 01-99
              // * third group must be 0001-9999

              foreach ($ssn_array as $group) {
              if ($group == 0) {
              return false;
              }
              }

              if ($ssn_array[0] == 666 || $ssn_array[0] > 899) {
              return false;
              }

              return true;
              }





              share|improve this answer























                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1517026%2fhow-can-i-validate-us-social-security-number%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                8 Answers
                8






                active

                oldest

                votes








                8 Answers
                8






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                22














                UPDATE



                On June 25, 2011, the SSA changed the SSN assignment process to "SSN randomization".[27] SSN randomization affects the SSN assignment process in the following ways:



                It eliminates the geographical significance of the first three digits of the SSN, previously referred to as the Area Number, by no longer allocating the Area Numbers for assignment to individuals in specific states.
                It eliminates the significance of the highest Group Number and, as a result, the High Group List is frozen in time and can be used for validation of SSNs issued prior to the randomization implementation date.
                Previously unassigned Area Numbers have been introduced for assignment excluding Area Numbers 000, 666 and 900–999.



                New Rules




                • The Social Security number is a nine-digit number in the format "AAA-GG-SSSS". The number is divided into three parts.

                • The middle two digits are the Group Number. The Group Numbers range from 01 to 99.

                • The last four digits are Serial Numbers. They represent a straight numerical sequence of digits from 0001 to 9999 within the group.

                • Some special numbers are never allocated:


                  • Numbers with all zeros in any digit group (000-##-####, ###-00-####, ###-##-0000).

                  • Numbers with 666 or 900-999 (Individual Taxpayer Identification Number) in the first digit group.



                • SSNs used in advertising have rendered those numbers invalid.


                http://en.wikipedia.org/wiki/Social_Security_number#Structure



                Previous Answer



                Here's the most-complete description of the makeup of an SSN that I have found.






                share|improve this answer





















                • 1





                  @user2864740: I have updated the answer to reflect the June 2011 changes.

                  – Eric J.
                  Jan 26 '15 at 22:12











                • Very interesting.

                  – Jeffpowrs
                  Oct 22 '15 at 21:37











                • great answer. thank you.

                  – catbadger
                  Feb 21 '18 at 21:31
















                22














                UPDATE



                On June 25, 2011, the SSA changed the SSN assignment process to "SSN randomization".[27] SSN randomization affects the SSN assignment process in the following ways:



                It eliminates the geographical significance of the first three digits of the SSN, previously referred to as the Area Number, by no longer allocating the Area Numbers for assignment to individuals in specific states.
                It eliminates the significance of the highest Group Number and, as a result, the High Group List is frozen in time and can be used for validation of SSNs issued prior to the randomization implementation date.
                Previously unassigned Area Numbers have been introduced for assignment excluding Area Numbers 000, 666 and 900–999.



                New Rules




                • The Social Security number is a nine-digit number in the format "AAA-GG-SSSS". The number is divided into three parts.

                • The middle two digits are the Group Number. The Group Numbers range from 01 to 99.

                • The last four digits are Serial Numbers. They represent a straight numerical sequence of digits from 0001 to 9999 within the group.

                • Some special numbers are never allocated:


                  • Numbers with all zeros in any digit group (000-##-####, ###-00-####, ###-##-0000).

                  • Numbers with 666 or 900-999 (Individual Taxpayer Identification Number) in the first digit group.



                • SSNs used in advertising have rendered those numbers invalid.


                http://en.wikipedia.org/wiki/Social_Security_number#Structure



                Previous Answer



                Here's the most-complete description of the makeup of an SSN that I have found.






                share|improve this answer





















                • 1





                  @user2864740: I have updated the answer to reflect the June 2011 changes.

                  – Eric J.
                  Jan 26 '15 at 22:12











                • Very interesting.

                  – Jeffpowrs
                  Oct 22 '15 at 21:37











                • great answer. thank you.

                  – catbadger
                  Feb 21 '18 at 21:31














                22












                22








                22







                UPDATE



                On June 25, 2011, the SSA changed the SSN assignment process to "SSN randomization".[27] SSN randomization affects the SSN assignment process in the following ways:



                It eliminates the geographical significance of the first three digits of the SSN, previously referred to as the Area Number, by no longer allocating the Area Numbers for assignment to individuals in specific states.
                It eliminates the significance of the highest Group Number and, as a result, the High Group List is frozen in time and can be used for validation of SSNs issued prior to the randomization implementation date.
                Previously unassigned Area Numbers have been introduced for assignment excluding Area Numbers 000, 666 and 900–999.



                New Rules




                • The Social Security number is a nine-digit number in the format "AAA-GG-SSSS". The number is divided into three parts.

                • The middle two digits are the Group Number. The Group Numbers range from 01 to 99.

                • The last four digits are Serial Numbers. They represent a straight numerical sequence of digits from 0001 to 9999 within the group.

                • Some special numbers are never allocated:


                  • Numbers with all zeros in any digit group (000-##-####, ###-00-####, ###-##-0000).

                  • Numbers with 666 or 900-999 (Individual Taxpayer Identification Number) in the first digit group.



                • SSNs used in advertising have rendered those numbers invalid.


                http://en.wikipedia.org/wiki/Social_Security_number#Structure



                Previous Answer



                Here's the most-complete description of the makeup of an SSN that I have found.






                share|improve this answer















                UPDATE



                On June 25, 2011, the SSA changed the SSN assignment process to "SSN randomization".[27] SSN randomization affects the SSN assignment process in the following ways:



                It eliminates the geographical significance of the first three digits of the SSN, previously referred to as the Area Number, by no longer allocating the Area Numbers for assignment to individuals in specific states.
                It eliminates the significance of the highest Group Number and, as a result, the High Group List is frozen in time and can be used for validation of SSNs issued prior to the randomization implementation date.
                Previously unassigned Area Numbers have been introduced for assignment excluding Area Numbers 000, 666 and 900–999.



                New Rules




                • The Social Security number is a nine-digit number in the format "AAA-GG-SSSS". The number is divided into three parts.

                • The middle two digits are the Group Number. The Group Numbers range from 01 to 99.

                • The last four digits are Serial Numbers. They represent a straight numerical sequence of digits from 0001 to 9999 within the group.

                • Some special numbers are never allocated:


                  • Numbers with all zeros in any digit group (000-##-####, ###-00-####, ###-##-0000).

                  • Numbers with 666 or 900-999 (Individual Taxpayer Identification Number) in the first digit group.



                • SSNs used in advertising have rendered those numbers invalid.


                http://en.wikipedia.org/wiki/Social_Security_number#Structure



                Previous Answer



                Here's the most-complete description of the makeup of an SSN that I have found.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jan 26 '15 at 22:17

























                answered Oct 4 '09 at 18:25









                Eric J.Eric J.

                120k47265492




                120k47265492








                • 1





                  @user2864740: I have updated the answer to reflect the June 2011 changes.

                  – Eric J.
                  Jan 26 '15 at 22:12











                • Very interesting.

                  – Jeffpowrs
                  Oct 22 '15 at 21:37











                • great answer. thank you.

                  – catbadger
                  Feb 21 '18 at 21:31














                • 1





                  @user2864740: I have updated the answer to reflect the June 2011 changes.

                  – Eric J.
                  Jan 26 '15 at 22:12











                • Very interesting.

                  – Jeffpowrs
                  Oct 22 '15 at 21:37











                • great answer. thank you.

                  – catbadger
                  Feb 21 '18 at 21:31








                1




                1





                @user2864740: I have updated the answer to reflect the June 2011 changes.

                – Eric J.
                Jan 26 '15 at 22:12





                @user2864740: I have updated the answer to reflect the June 2011 changes.

                – Eric J.
                Jan 26 '15 at 22:12













                Very interesting.

                – Jeffpowrs
                Oct 22 '15 at 21:37





                Very interesting.

                – Jeffpowrs
                Oct 22 '15 at 21:37













                great answer. thank you.

                – catbadger
                Feb 21 '18 at 21:31





                great answer. thank you.

                – catbadger
                Feb 21 '18 at 21:31













                16














                As of 2011 SSN's are completely randomized (http://www.socialsecurity.gov/employer/randomization.html)



                The only real rules left are:




                • Cannot start with 900-999 (although the Individual Taxpayer Identification Number, which can be used like an SSN by temporary residents and undocumented/DACA/DAPA immigrants in some situations, is in the same format and does start with 9)

                • Cannot start with 666

                • Cannot start with 000

                • Must be 9 numeric digits or 11 with the 2 dashes

                • Cannot be any of the known fakes;


                  • "078051120" — Woolworth Wallet Fiasco

                  • "219099999" — Was used in an ad by the Social Security Administration



                • Many people exclude repeating an sequential numbers as well, although these are now technically valid, and I feel sorry for the poor schmuck's who gets assigned these.






                share|improve this answer


























                • According to the SSN randomization FAQ, the group (middle 2 digits) or serial number (last 4) also cannot be all 0s.

                  – Nick Chammas
                  Mar 27 '17 at 20:03
















                16














                As of 2011 SSN's are completely randomized (http://www.socialsecurity.gov/employer/randomization.html)



                The only real rules left are:




                • Cannot start with 900-999 (although the Individual Taxpayer Identification Number, which can be used like an SSN by temporary residents and undocumented/DACA/DAPA immigrants in some situations, is in the same format and does start with 9)

                • Cannot start with 666

                • Cannot start with 000

                • Must be 9 numeric digits or 11 with the 2 dashes

                • Cannot be any of the known fakes;


                  • "078051120" — Woolworth Wallet Fiasco

                  • "219099999" — Was used in an ad by the Social Security Administration



                • Many people exclude repeating an sequential numbers as well, although these are now technically valid, and I feel sorry for the poor schmuck's who gets assigned these.






                share|improve this answer


























                • According to the SSN randomization FAQ, the group (middle 2 digits) or serial number (last 4) also cannot be all 0s.

                  – Nick Chammas
                  Mar 27 '17 at 20:03














                16












                16








                16







                As of 2011 SSN's are completely randomized (http://www.socialsecurity.gov/employer/randomization.html)



                The only real rules left are:




                • Cannot start with 900-999 (although the Individual Taxpayer Identification Number, which can be used like an SSN by temporary residents and undocumented/DACA/DAPA immigrants in some situations, is in the same format and does start with 9)

                • Cannot start with 666

                • Cannot start with 000

                • Must be 9 numeric digits or 11 with the 2 dashes

                • Cannot be any of the known fakes;


                  • "078051120" — Woolworth Wallet Fiasco

                  • "219099999" — Was used in an ad by the Social Security Administration



                • Many people exclude repeating an sequential numbers as well, although these are now technically valid, and I feel sorry for the poor schmuck's who gets assigned these.






                share|improve this answer















                As of 2011 SSN's are completely randomized (http://www.socialsecurity.gov/employer/randomization.html)



                The only real rules left are:




                • Cannot start with 900-999 (although the Individual Taxpayer Identification Number, which can be used like an SSN by temporary residents and undocumented/DACA/DAPA immigrants in some situations, is in the same format and does start with 9)

                • Cannot start with 666

                • Cannot start with 000

                • Must be 9 numeric digits or 11 with the 2 dashes

                • Cannot be any of the known fakes;


                  • "078051120" — Woolworth Wallet Fiasco

                  • "219099999" — Was used in an ad by the Social Security Administration



                • Many people exclude repeating an sequential numbers as well, although these are now technically valid, and I feel sorry for the poor schmuck's who gets assigned these.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 23 '17 at 0:01









                user833771

                16318




                16318










                answered Aug 22 '13 at 16:13









                LouisLouis

                16112




                16112













                • According to the SSN randomization FAQ, the group (middle 2 digits) or serial number (last 4) also cannot be all 0s.

                  – Nick Chammas
                  Mar 27 '17 at 20:03



















                • According to the SSN randomization FAQ, the group (middle 2 digits) or serial number (last 4) also cannot be all 0s.

                  – Nick Chammas
                  Mar 27 '17 at 20:03

















                According to the SSN randomization FAQ, the group (middle 2 digits) or serial number (last 4) also cannot be all 0s.

                – Nick Chammas
                Mar 27 '17 at 20:03





                According to the SSN randomization FAQ, the group (middle 2 digits) or serial number (last 4) also cannot be all 0s.

                – Nick Chammas
                Mar 27 '17 at 20:03











                14





                +25









                Answer 5 years after initial question due to changes in validation rules by the Social Security Administration. Also there are Specific numbers to invalidate according to this link.



                As per my near-2-year-old answer I also left out isNumeric(ssn) because the field is a numeric and already strips characters before calling the validate function.



                // validate social security number with ssn parameter as string
                function validateSSN(ssn) {
                // find area number (1st 3 digits, no longer actually signifies area)
                var area = parseInt(ssn.substring(0, 3));
                return (
                // 9 characters
                ssn.length === 9 &&
                // no set can start with zero
                ssn.match(/^[1-9][0-9]{2}[1-9][0-9]{1}[1-9][0-9]{3}/) &&
                // disallow Satan's minions from becoming residents of the US
                area !== 666 &&
                // it's over 900
                area < 900 &&
                // fun fact: some idiot boss put his secretary's ssn in wallets
                // he sold, now it "belongs" to 40000 people
                ssn !== '078051120' &&
                // was used in an ad by the Social Security Administration
                ssn !== '219099999'
                );
                }


                According to updated information there are no other checks to perform.






                share|improve this answer




























                  14





                  +25









                  Answer 5 years after initial question due to changes in validation rules by the Social Security Administration. Also there are Specific numbers to invalidate according to this link.



                  As per my near-2-year-old answer I also left out isNumeric(ssn) because the field is a numeric and already strips characters before calling the validate function.



                  // validate social security number with ssn parameter as string
                  function validateSSN(ssn) {
                  // find area number (1st 3 digits, no longer actually signifies area)
                  var area = parseInt(ssn.substring(0, 3));
                  return (
                  // 9 characters
                  ssn.length === 9 &&
                  // no set can start with zero
                  ssn.match(/^[1-9][0-9]{2}[1-9][0-9]{1}[1-9][0-9]{3}/) &&
                  // disallow Satan's minions from becoming residents of the US
                  area !== 666 &&
                  // it's over 900
                  area < 900 &&
                  // fun fact: some idiot boss put his secretary's ssn in wallets
                  // he sold, now it "belongs" to 40000 people
                  ssn !== '078051120' &&
                  // was used in an ad by the Social Security Administration
                  ssn !== '219099999'
                  );
                  }


                  According to updated information there are no other checks to perform.






                  share|improve this answer


























                    14





                    +25







                    14





                    +25



                    14




                    +25





                    Answer 5 years after initial question due to changes in validation rules by the Social Security Administration. Also there are Specific numbers to invalidate according to this link.



                    As per my near-2-year-old answer I also left out isNumeric(ssn) because the field is a numeric and already strips characters before calling the validate function.



                    // validate social security number with ssn parameter as string
                    function validateSSN(ssn) {
                    // find area number (1st 3 digits, no longer actually signifies area)
                    var area = parseInt(ssn.substring(0, 3));
                    return (
                    // 9 characters
                    ssn.length === 9 &&
                    // no set can start with zero
                    ssn.match(/^[1-9][0-9]{2}[1-9][0-9]{1}[1-9][0-9]{3}/) &&
                    // disallow Satan's minions from becoming residents of the US
                    area !== 666 &&
                    // it's over 900
                    area < 900 &&
                    // fun fact: some idiot boss put his secretary's ssn in wallets
                    // he sold, now it "belongs" to 40000 people
                    ssn !== '078051120' &&
                    // was used in an ad by the Social Security Administration
                    ssn !== '219099999'
                    );
                    }


                    According to updated information there are no other checks to perform.






                    share|improve this answer













                    Answer 5 years after initial question due to changes in validation rules by the Social Security Administration. Also there are Specific numbers to invalidate according to this link.



                    As per my near-2-year-old answer I also left out isNumeric(ssn) because the field is a numeric and already strips characters before calling the validate function.



                    // validate social security number with ssn parameter as string
                    function validateSSN(ssn) {
                    // find area number (1st 3 digits, no longer actually signifies area)
                    var area = parseInt(ssn.substring(0, 3));
                    return (
                    // 9 characters
                    ssn.length === 9 &&
                    // no set can start with zero
                    ssn.match(/^[1-9][0-9]{2}[1-9][0-9]{1}[1-9][0-9]{3}/) &&
                    // disallow Satan's minions from becoming residents of the US
                    area !== 666 &&
                    // it's over 900
                    area < 900 &&
                    // fun fact: some idiot boss put his secretary's ssn in wallets
                    // he sold, now it "belongs" to 40000 people
                    ssn !== '078051120' &&
                    // was used in an ad by the Social Security Administration
                    ssn !== '219099999'
                    );
                    }


                    According to updated information there are no other checks to perform.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 27 '15 at 15:14









                    MaKRMaKR

                    1,3861429




                    1,3861429























                        11














                        It's all at socialsecurity.gov: Numbering scheme, allocations, highest numbers updated monthly.






                        share|improve this answer



















                        • 2





                          Yes. In essence, you can't really validate a US social security number. There's no check digit, for instance. About the best you can do is toss stuff that's obviously invalid. Also bear in mind that the possible domain of a US Social Security Number is 1 billion discrete values (0-999999999). Given that there are gaps in the actual domain due to the allocation schema and that there are more than 300m people currently alive in the US, most of whom have social security numbers, nearly a third of the possible domain is taken. Won't be long until we start seeing collisions. That'll be fun.

                          – Nicholas Carey
                          May 2 '13 at 17:34






                        • 1





                          This answer now refers to outdated information.

                          – user2864740
                          Jan 26 '15 at 21:44
















                        11














                        It's all at socialsecurity.gov: Numbering scheme, allocations, highest numbers updated monthly.






                        share|improve this answer



















                        • 2





                          Yes. In essence, you can't really validate a US social security number. There's no check digit, for instance. About the best you can do is toss stuff that's obviously invalid. Also bear in mind that the possible domain of a US Social Security Number is 1 billion discrete values (0-999999999). Given that there are gaps in the actual domain due to the allocation schema and that there are more than 300m people currently alive in the US, most of whom have social security numbers, nearly a third of the possible domain is taken. Won't be long until we start seeing collisions. That'll be fun.

                          – Nicholas Carey
                          May 2 '13 at 17:34






                        • 1





                          This answer now refers to outdated information.

                          – user2864740
                          Jan 26 '15 at 21:44














                        11












                        11








                        11







                        It's all at socialsecurity.gov: Numbering scheme, allocations, highest numbers updated monthly.






                        share|improve this answer













                        It's all at socialsecurity.gov: Numbering scheme, allocations, highest numbers updated monthly.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Oct 4 '09 at 18:25









                        ZedZed

                        46.9k56497




                        46.9k56497








                        • 2





                          Yes. In essence, you can't really validate a US social security number. There's no check digit, for instance. About the best you can do is toss stuff that's obviously invalid. Also bear in mind that the possible domain of a US Social Security Number is 1 billion discrete values (0-999999999). Given that there are gaps in the actual domain due to the allocation schema and that there are more than 300m people currently alive in the US, most of whom have social security numbers, nearly a third of the possible domain is taken. Won't be long until we start seeing collisions. That'll be fun.

                          – Nicholas Carey
                          May 2 '13 at 17:34






                        • 1





                          This answer now refers to outdated information.

                          – user2864740
                          Jan 26 '15 at 21:44














                        • 2





                          Yes. In essence, you can't really validate a US social security number. There's no check digit, for instance. About the best you can do is toss stuff that's obviously invalid. Also bear in mind that the possible domain of a US Social Security Number is 1 billion discrete values (0-999999999). Given that there are gaps in the actual domain due to the allocation schema and that there are more than 300m people currently alive in the US, most of whom have social security numbers, nearly a third of the possible domain is taken. Won't be long until we start seeing collisions. That'll be fun.

                          – Nicholas Carey
                          May 2 '13 at 17:34






                        • 1





                          This answer now refers to outdated information.

                          – user2864740
                          Jan 26 '15 at 21:44








                        2




                        2





                        Yes. In essence, you can't really validate a US social security number. There's no check digit, for instance. About the best you can do is toss stuff that's obviously invalid. Also bear in mind that the possible domain of a US Social Security Number is 1 billion discrete values (0-999999999). Given that there are gaps in the actual domain due to the allocation schema and that there are more than 300m people currently alive in the US, most of whom have social security numbers, nearly a third of the possible domain is taken. Won't be long until we start seeing collisions. That'll be fun.

                        – Nicholas Carey
                        May 2 '13 at 17:34





                        Yes. In essence, you can't really validate a US social security number. There's no check digit, for instance. About the best you can do is toss stuff that's obviously invalid. Also bear in mind that the possible domain of a US Social Security Number is 1 billion discrete values (0-999999999). Given that there are gaps in the actual domain due to the allocation schema and that there are more than 300m people currently alive in the US, most of whom have social security numbers, nearly a third of the possible domain is taken. Won't be long until we start seeing collisions. That'll be fun.

                        – Nicholas Carey
                        May 2 '13 at 17:34




                        1




                        1





                        This answer now refers to outdated information.

                        – user2864740
                        Jan 26 '15 at 21:44





                        This answer now refers to outdated information.

                        – user2864740
                        Jan 26 '15 at 21:44











                        3














                        This is obviously an old post, but I found some ways to shorten it. Also there are a few specific numbers to invalidate according to this link:
                        http://www.snopes.com/business/taxes/woolworth.asp



                        Here's how I did it. I could have used regexes for repeating numbers, but with specific ones to invalidate we might as well add ones through fives to that list (over 5 will invalidate anyways due to area number validation). I also left out isNumeric(ssn) because the field is a numeric and already strips characters before calling the validate function.



                        function validateSSN(ssn) {
                        // validate format (no all zeroes, length 9
                        if (!ssn.match(/^[1-9][0-9]{2}[1-9][0-9]{1}[1-9][0-9]{3}/)
                        || ssn.length!=9) return false;

                        // validate area number (1st 3 digits)
                        var area=parseInt(ssn.substring(0, 3));
                        // standard railroad numbers (pre-1963)
                        if (area>649 && !(area>=700 && area<=728)) return false;

                        // disallow specific invalid number
                        if (ssn=='078051120' || // fun fact: some idiot boss put his
                        // secretary's ssn in wallets he sold,
                        // now this is 40000 people's ssn
                        ssn=='219099999' || // was used in an ad by the Social Security
                        // Administration
                        ssn=='123456789' || // although valid it's not yet assigned and
                        // you're not likely to meet the person who
                        // will get it
                        ssn=='123121234' || // probably is assigned to someone but more
                        // likely to find someone trying to fake a
                        // number (next is same)
                        ssn=='321214321' || // all the rest are likely potentially
                        // valid, but most likely these numbers are
                        // abused
                        ssn=='111111111' ||
                        ssn=='222222222' ||
                        ssn=='333333333' ||
                        ssn=='444444444' ||
                        ssn=='555555555') return false;

                        return true;
                        }





                        share|improve this answer





















                        • 2





                          These rules are silly. If someone is going to fake '321214321' they might as well fake '102319982' (and yes, I just typed that in randomly). Only the first two specific rules have any substantiated claim AFAIK. In addition the previous excluded ranges are now allowed.

                          – user2864740
                          Jan 26 '15 at 21:41


















                        3














                        This is obviously an old post, but I found some ways to shorten it. Also there are a few specific numbers to invalidate according to this link:
                        http://www.snopes.com/business/taxes/woolworth.asp



                        Here's how I did it. I could have used regexes for repeating numbers, but with specific ones to invalidate we might as well add ones through fives to that list (over 5 will invalidate anyways due to area number validation). I also left out isNumeric(ssn) because the field is a numeric and already strips characters before calling the validate function.



                        function validateSSN(ssn) {
                        // validate format (no all zeroes, length 9
                        if (!ssn.match(/^[1-9][0-9]{2}[1-9][0-9]{1}[1-9][0-9]{3}/)
                        || ssn.length!=9) return false;

                        // validate area number (1st 3 digits)
                        var area=parseInt(ssn.substring(0, 3));
                        // standard railroad numbers (pre-1963)
                        if (area>649 && !(area>=700 && area<=728)) return false;

                        // disallow specific invalid number
                        if (ssn=='078051120' || // fun fact: some idiot boss put his
                        // secretary's ssn in wallets he sold,
                        // now this is 40000 people's ssn
                        ssn=='219099999' || // was used in an ad by the Social Security
                        // Administration
                        ssn=='123456789' || // although valid it's not yet assigned and
                        // you're not likely to meet the person who
                        // will get it
                        ssn=='123121234' || // probably is assigned to someone but more
                        // likely to find someone trying to fake a
                        // number (next is same)
                        ssn=='321214321' || // all the rest are likely potentially
                        // valid, but most likely these numbers are
                        // abused
                        ssn=='111111111' ||
                        ssn=='222222222' ||
                        ssn=='333333333' ||
                        ssn=='444444444' ||
                        ssn=='555555555') return false;

                        return true;
                        }





                        share|improve this answer





















                        • 2





                          These rules are silly. If someone is going to fake '321214321' they might as well fake '102319982' (and yes, I just typed that in randomly). Only the first two specific rules have any substantiated claim AFAIK. In addition the previous excluded ranges are now allowed.

                          – user2864740
                          Jan 26 '15 at 21:41
















                        3












                        3








                        3







                        This is obviously an old post, but I found some ways to shorten it. Also there are a few specific numbers to invalidate according to this link:
                        http://www.snopes.com/business/taxes/woolworth.asp



                        Here's how I did it. I could have used regexes for repeating numbers, but with specific ones to invalidate we might as well add ones through fives to that list (over 5 will invalidate anyways due to area number validation). I also left out isNumeric(ssn) because the field is a numeric and already strips characters before calling the validate function.



                        function validateSSN(ssn) {
                        // validate format (no all zeroes, length 9
                        if (!ssn.match(/^[1-9][0-9]{2}[1-9][0-9]{1}[1-9][0-9]{3}/)
                        || ssn.length!=9) return false;

                        // validate area number (1st 3 digits)
                        var area=parseInt(ssn.substring(0, 3));
                        // standard railroad numbers (pre-1963)
                        if (area>649 && !(area>=700 && area<=728)) return false;

                        // disallow specific invalid number
                        if (ssn=='078051120' || // fun fact: some idiot boss put his
                        // secretary's ssn in wallets he sold,
                        // now this is 40000 people's ssn
                        ssn=='219099999' || // was used in an ad by the Social Security
                        // Administration
                        ssn=='123456789' || // although valid it's not yet assigned and
                        // you're not likely to meet the person who
                        // will get it
                        ssn=='123121234' || // probably is assigned to someone but more
                        // likely to find someone trying to fake a
                        // number (next is same)
                        ssn=='321214321' || // all the rest are likely potentially
                        // valid, but most likely these numbers are
                        // abused
                        ssn=='111111111' ||
                        ssn=='222222222' ||
                        ssn=='333333333' ||
                        ssn=='444444444' ||
                        ssn=='555555555') return false;

                        return true;
                        }





                        share|improve this answer















                        This is obviously an old post, but I found some ways to shorten it. Also there are a few specific numbers to invalidate according to this link:
                        http://www.snopes.com/business/taxes/woolworth.asp



                        Here's how I did it. I could have used regexes for repeating numbers, but with specific ones to invalidate we might as well add ones through fives to that list (over 5 will invalidate anyways due to area number validation). I also left out isNumeric(ssn) because the field is a numeric and already strips characters before calling the validate function.



                        function validateSSN(ssn) {
                        // validate format (no all zeroes, length 9
                        if (!ssn.match(/^[1-9][0-9]{2}[1-9][0-9]{1}[1-9][0-9]{3}/)
                        || ssn.length!=9) return false;

                        // validate area number (1st 3 digits)
                        var area=parseInt(ssn.substring(0, 3));
                        // standard railroad numbers (pre-1963)
                        if (area>649 && !(area>=700 && area<=728)) return false;

                        // disallow specific invalid number
                        if (ssn=='078051120' || // fun fact: some idiot boss put his
                        // secretary's ssn in wallets he sold,
                        // now this is 40000 people's ssn
                        ssn=='219099999' || // was used in an ad by the Social Security
                        // Administration
                        ssn=='123456789' || // although valid it's not yet assigned and
                        // you're not likely to meet the person who
                        // will get it
                        ssn=='123121234' || // probably is assigned to someone but more
                        // likely to find someone trying to fake a
                        // number (next is same)
                        ssn=='321214321' || // all the rest are likely potentially
                        // valid, but most likely these numbers are
                        // abused
                        ssn=='111111111' ||
                        ssn=='222222222' ||
                        ssn=='333333333' ||
                        ssn=='444444444' ||
                        ssn=='555555555') return false;

                        return true;
                        }






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Jan 26 '15 at 21:31

























                        answered May 2 '13 at 17:10









                        MaKRMaKR

                        1,3861429




                        1,3861429








                        • 2





                          These rules are silly. If someone is going to fake '321214321' they might as well fake '102319982' (and yes, I just typed that in randomly). Only the first two specific rules have any substantiated claim AFAIK. In addition the previous excluded ranges are now allowed.

                          – user2864740
                          Jan 26 '15 at 21:41
















                        • 2





                          These rules are silly. If someone is going to fake '321214321' they might as well fake '102319982' (and yes, I just typed that in randomly). Only the first two specific rules have any substantiated claim AFAIK. In addition the previous excluded ranges are now allowed.

                          – user2864740
                          Jan 26 '15 at 21:41










                        2




                        2





                        These rules are silly. If someone is going to fake '321214321' they might as well fake '102319982' (and yes, I just typed that in randomly). Only the first two specific rules have any substantiated claim AFAIK. In addition the previous excluded ranges are now allowed.

                        – user2864740
                        Jan 26 '15 at 21:41







                        These rules are silly. If someone is going to fake '321214321' they might as well fake '102319982' (and yes, I just typed that in randomly). Only the first two specific rules have any substantiated claim AFAIK. In addition the previous excluded ranges are now allowed.

                        – user2864740
                        Jan 26 '15 at 21:41













                        1














                        As of the randomizing of social security numbers post-911, the entries in the 900 series and even 666 are now potentially valid numbers.



                        The only certain things at this point in time appear to be:

                        the first group of 3 will never be 000

                        the middle group pair will never be 00

                        and the last four will never be 0000



                        You can perform some testing by first testing to ensure that the numeric value of the entry is >= 1010001 [and < 1000000000] (a ssan of 001-01-0001 appears to be the lowest legitimately assigned). Then you can proceed to check for 00 in positions 4 and 5, and 0000 in the last four.






                        share|improve this answer





















                        • 3





                          Please provide an authoratative reference for the first sentence and the following assumptions/rules. It goes against other (previous answers) and government documentation: "Previously unassigned area numbers were introduced for assignment excluding area numbers 000, 666 and 900-999."

                          – user2864740
                          Jan 26 '15 at 21:39


















                        1














                        As of the randomizing of social security numbers post-911, the entries in the 900 series and even 666 are now potentially valid numbers.



                        The only certain things at this point in time appear to be:

                        the first group of 3 will never be 000

                        the middle group pair will never be 00

                        and the last four will never be 0000



                        You can perform some testing by first testing to ensure that the numeric value of the entry is >= 1010001 [and < 1000000000] (a ssan of 001-01-0001 appears to be the lowest legitimately assigned). Then you can proceed to check for 00 in positions 4 and 5, and 0000 in the last four.






                        share|improve this answer





















                        • 3





                          Please provide an authoratative reference for the first sentence and the following assumptions/rules. It goes against other (previous answers) and government documentation: "Previously unassigned area numbers were introduced for assignment excluding area numbers 000, 666 and 900-999."

                          – user2864740
                          Jan 26 '15 at 21:39
















                        1












                        1








                        1







                        As of the randomizing of social security numbers post-911, the entries in the 900 series and even 666 are now potentially valid numbers.



                        The only certain things at this point in time appear to be:

                        the first group of 3 will never be 000

                        the middle group pair will never be 00

                        and the last four will never be 0000



                        You can perform some testing by first testing to ensure that the numeric value of the entry is >= 1010001 [and < 1000000000] (a ssan of 001-01-0001 appears to be the lowest legitimately assigned). Then you can proceed to check for 00 in positions 4 and 5, and 0000 in the last four.






                        share|improve this answer















                        As of the randomizing of social security numbers post-911, the entries in the 900 series and even 666 are now potentially valid numbers.



                        The only certain things at this point in time appear to be:

                        the first group of 3 will never be 000

                        the middle group pair will never be 00

                        and the last four will never be 0000



                        You can perform some testing by first testing to ensure that the numeric value of the entry is >= 1010001 [and < 1000000000] (a ssan of 001-01-0001 appears to be the lowest legitimately assigned). Then you can proceed to check for 00 in positions 4 and 5, and 0000 in the last four.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Jan 26 '15 at 16:38









                        AbcAeffchen

                        8,520123552




                        8,520123552










                        answered Jan 26 '15 at 16:16









                        2kmaro2kmaro

                        111




                        111








                        • 3





                          Please provide an authoratative reference for the first sentence and the following assumptions/rules. It goes against other (previous answers) and government documentation: "Previously unassigned area numbers were introduced for assignment excluding area numbers 000, 666 and 900-999."

                          – user2864740
                          Jan 26 '15 at 21:39
















                        • 3





                          Please provide an authoratative reference for the first sentence and the following assumptions/rules. It goes against other (previous answers) and government documentation: "Previously unassigned area numbers were introduced for assignment excluding area numbers 000, 666 and 900-999."

                          – user2864740
                          Jan 26 '15 at 21:39










                        3




                        3





                        Please provide an authoratative reference for the first sentence and the following assumptions/rules. It goes against other (previous answers) and government documentation: "Previously unassigned area numbers were introduced for assignment excluding area numbers 000, 666 and 900-999."

                        – user2864740
                        Jan 26 '15 at 21:39







                        Please provide an authoratative reference for the first sentence and the following assumptions/rules. It goes against other (previous answers) and government documentation: "Previously unassigned area numbers were introduced for assignment excluding area numbers 000, 666 and 900-999."

                        – user2864740
                        Jan 26 '15 at 21:39













                        1














                        I know this is an old question, but for the sake of others looking for answers, I figured I'd add a quick javascript function for checking that a given SSN is valid.



                        function checkSSN() {
                        var inputSSN = #YourInput#,
                        ssnRegex = new RegExp("^(9[0-9][0-9]|666|000|078051120|219099999|123456789|123121234|321214321)|^([0-8][0-9][0-9]00)|^([0-8][0-9][0-9][0-9][0-9]000)$"),
                        repeats = /^(.)1+$/;

                        //make sure we have 2 dashes in the input Social Security number
                        if( inputSSN.match(/./g).length === 2) {
                        //Once we have confirmed that there are the right number of dashes, remove them, and make sure that the resulting string is a number (you may or may not need this logic depending on the format of your input SSN.
                        inputSSN = inputSSN.replace(/-/g, "");

                        if(!isNaN(inputSSN)) {
                        //Test the input SSN against our regex to ensure that it doesn't contain any disqualifying combinations.
                        if(!ssnRegex.test(inputSSN)) {
                        //Make sure the input SSN isn't just a repeated number
                        if(!repeats.test(inputSSN)) {
                        //If it lands inside of this, we know it's a valid option for a social security number.
                        }
                        }
                        }
                        }


                        For the ssnRegex logic:



                        The first section handles if the SSN starts with a number 900-999, 666, 000, or one of the known disqualifying SSNs mentioned above.



                        ^(9[0-9][0-9]|666|000|078051120|219099999|123456789|123121234|321214321)



                        the second section ensures that the 2 digit portion isn't 00



                        ^([0-8][0-9][0-9]00)



                        The third section ensures that the last portion isn't 0000



                        ^([0-8][0-9][0-9][0-9][0-9]0000)



                        We additionally check to make sure they have inputted a number, and that they aren't just using a repeated number.






                        share|improve this answer




























                          1














                          I know this is an old question, but for the sake of others looking for answers, I figured I'd add a quick javascript function for checking that a given SSN is valid.



                          function checkSSN() {
                          var inputSSN = #YourInput#,
                          ssnRegex = new RegExp("^(9[0-9][0-9]|666|000|078051120|219099999|123456789|123121234|321214321)|^([0-8][0-9][0-9]00)|^([0-8][0-9][0-9][0-9][0-9]000)$"),
                          repeats = /^(.)1+$/;

                          //make sure we have 2 dashes in the input Social Security number
                          if( inputSSN.match(/./g).length === 2) {
                          //Once we have confirmed that there are the right number of dashes, remove them, and make sure that the resulting string is a number (you may or may not need this logic depending on the format of your input SSN.
                          inputSSN = inputSSN.replace(/-/g, "");

                          if(!isNaN(inputSSN)) {
                          //Test the input SSN against our regex to ensure that it doesn't contain any disqualifying combinations.
                          if(!ssnRegex.test(inputSSN)) {
                          //Make sure the input SSN isn't just a repeated number
                          if(!repeats.test(inputSSN)) {
                          //If it lands inside of this, we know it's a valid option for a social security number.
                          }
                          }
                          }
                          }


                          For the ssnRegex logic:



                          The first section handles if the SSN starts with a number 900-999, 666, 000, or one of the known disqualifying SSNs mentioned above.



                          ^(9[0-9][0-9]|666|000|078051120|219099999|123456789|123121234|321214321)



                          the second section ensures that the 2 digit portion isn't 00



                          ^([0-8][0-9][0-9]00)



                          The third section ensures that the last portion isn't 0000



                          ^([0-8][0-9][0-9][0-9][0-9]0000)



                          We additionally check to make sure they have inputted a number, and that they aren't just using a repeated number.






                          share|improve this answer


























                            1












                            1








                            1







                            I know this is an old question, but for the sake of others looking for answers, I figured I'd add a quick javascript function for checking that a given SSN is valid.



                            function checkSSN() {
                            var inputSSN = #YourInput#,
                            ssnRegex = new RegExp("^(9[0-9][0-9]|666|000|078051120|219099999|123456789|123121234|321214321)|^([0-8][0-9][0-9]00)|^([0-8][0-9][0-9][0-9][0-9]000)$"),
                            repeats = /^(.)1+$/;

                            //make sure we have 2 dashes in the input Social Security number
                            if( inputSSN.match(/./g).length === 2) {
                            //Once we have confirmed that there are the right number of dashes, remove them, and make sure that the resulting string is a number (you may or may not need this logic depending on the format of your input SSN.
                            inputSSN = inputSSN.replace(/-/g, "");

                            if(!isNaN(inputSSN)) {
                            //Test the input SSN against our regex to ensure that it doesn't contain any disqualifying combinations.
                            if(!ssnRegex.test(inputSSN)) {
                            //Make sure the input SSN isn't just a repeated number
                            if(!repeats.test(inputSSN)) {
                            //If it lands inside of this, we know it's a valid option for a social security number.
                            }
                            }
                            }
                            }


                            For the ssnRegex logic:



                            The first section handles if the SSN starts with a number 900-999, 666, 000, or one of the known disqualifying SSNs mentioned above.



                            ^(9[0-9][0-9]|666|000|078051120|219099999|123456789|123121234|321214321)



                            the second section ensures that the 2 digit portion isn't 00



                            ^([0-8][0-9][0-9]00)



                            The third section ensures that the last portion isn't 0000



                            ^([0-8][0-9][0-9][0-9][0-9]0000)



                            We additionally check to make sure they have inputted a number, and that they aren't just using a repeated number.






                            share|improve this answer













                            I know this is an old question, but for the sake of others looking for answers, I figured I'd add a quick javascript function for checking that a given SSN is valid.



                            function checkSSN() {
                            var inputSSN = #YourInput#,
                            ssnRegex = new RegExp("^(9[0-9][0-9]|666|000|078051120|219099999|123456789|123121234|321214321)|^([0-8][0-9][0-9]00)|^([0-8][0-9][0-9][0-9][0-9]000)$"),
                            repeats = /^(.)1+$/;

                            //make sure we have 2 dashes in the input Social Security number
                            if( inputSSN.match(/./g).length === 2) {
                            //Once we have confirmed that there are the right number of dashes, remove them, and make sure that the resulting string is a number (you may or may not need this logic depending on the format of your input SSN.
                            inputSSN = inputSSN.replace(/-/g, "");

                            if(!isNaN(inputSSN)) {
                            //Test the input SSN against our regex to ensure that it doesn't contain any disqualifying combinations.
                            if(!ssnRegex.test(inputSSN)) {
                            //Make sure the input SSN isn't just a repeated number
                            if(!repeats.test(inputSSN)) {
                            //If it lands inside of this, we know it's a valid option for a social security number.
                            }
                            }
                            }
                            }


                            For the ssnRegex logic:



                            The first section handles if the SSN starts with a number 900-999, 666, 000, or one of the known disqualifying SSNs mentioned above.



                            ^(9[0-9][0-9]|666|000|078051120|219099999|123456789|123121234|321214321)



                            the second section ensures that the 2 digit portion isn't 00



                            ^([0-8][0-9][0-9]00)



                            The third section ensures that the last portion isn't 0000



                            ^([0-8][0-9][0-9][0-9][0-9]0000)



                            We additionally check to make sure they have inputted a number, and that they aren't just using a repeated number.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 22 '16 at 23:59









                            GuyThreepwood64GuyThreepwood64

                            211




                            211























                                0














                                Here is my PHP version



                                /**
                                * Validate SSN - must be in format AAA-GG-SSSS or AAAGGSSSS
                                *
                                * @param $ssn
                                * @return bool
                                */
                                function validate_ssn($ssn) {

                                $ssnTrimmed = trim($ssn);

                                // Must be in format AAA-GG-SSSS or AAAGGSSSS
                                if ( ! preg_match("/^([0-9]{9}|[0-9]{3}-[0-9]{2}-[0-9]{4})$/", $ssnTrimmed)) {
                                return false;
                                }

                                // Split groups into an array
                                $ssnFormatted = (strlen($ssnTrimmed) == 9) ? preg_replace("/^([0-9]{3})([0-9]{2})([0-9]{4})$/", "$1-$2-$3", $ssnTrimmed) : $ssnTrimmed;
                                $ssn_array = explode('-', $ssnFormatted);

                                // number groups must follow these rules:
                                // * no single group can have all 0's
                                // * first group cannot be 666, 900-999
                                // * second group must be 01-99
                                // * third group must be 0001-9999

                                foreach ($ssn_array as $group) {
                                if ($group == 0) {
                                return false;
                                }
                                }

                                if ($ssn_array[0] == 666 || $ssn_array[0] > 899) {
                                return false;
                                }

                                return true;
                                }





                                share|improve this answer




























                                  0














                                  Here is my PHP version



                                  /**
                                  * Validate SSN - must be in format AAA-GG-SSSS or AAAGGSSSS
                                  *
                                  * @param $ssn
                                  * @return bool
                                  */
                                  function validate_ssn($ssn) {

                                  $ssnTrimmed = trim($ssn);

                                  // Must be in format AAA-GG-SSSS or AAAGGSSSS
                                  if ( ! preg_match("/^([0-9]{9}|[0-9]{3}-[0-9]{2}-[0-9]{4})$/", $ssnTrimmed)) {
                                  return false;
                                  }

                                  // Split groups into an array
                                  $ssnFormatted = (strlen($ssnTrimmed) == 9) ? preg_replace("/^([0-9]{3})([0-9]{2})([0-9]{4})$/", "$1-$2-$3", $ssnTrimmed) : $ssnTrimmed;
                                  $ssn_array = explode('-', $ssnFormatted);

                                  // number groups must follow these rules:
                                  // * no single group can have all 0's
                                  // * first group cannot be 666, 900-999
                                  // * second group must be 01-99
                                  // * third group must be 0001-9999

                                  foreach ($ssn_array as $group) {
                                  if ($group == 0) {
                                  return false;
                                  }
                                  }

                                  if ($ssn_array[0] == 666 || $ssn_array[0] > 899) {
                                  return false;
                                  }

                                  return true;
                                  }





                                  share|improve this answer


























                                    0












                                    0








                                    0







                                    Here is my PHP version



                                    /**
                                    * Validate SSN - must be in format AAA-GG-SSSS or AAAGGSSSS
                                    *
                                    * @param $ssn
                                    * @return bool
                                    */
                                    function validate_ssn($ssn) {

                                    $ssnTrimmed = trim($ssn);

                                    // Must be in format AAA-GG-SSSS or AAAGGSSSS
                                    if ( ! preg_match("/^([0-9]{9}|[0-9]{3}-[0-9]{2}-[0-9]{4})$/", $ssnTrimmed)) {
                                    return false;
                                    }

                                    // Split groups into an array
                                    $ssnFormatted = (strlen($ssnTrimmed) == 9) ? preg_replace("/^([0-9]{3})([0-9]{2})([0-9]{4})$/", "$1-$2-$3", $ssnTrimmed) : $ssnTrimmed;
                                    $ssn_array = explode('-', $ssnFormatted);

                                    // number groups must follow these rules:
                                    // * no single group can have all 0's
                                    // * first group cannot be 666, 900-999
                                    // * second group must be 01-99
                                    // * third group must be 0001-9999

                                    foreach ($ssn_array as $group) {
                                    if ($group == 0) {
                                    return false;
                                    }
                                    }

                                    if ($ssn_array[0] == 666 || $ssn_array[0] > 899) {
                                    return false;
                                    }

                                    return true;
                                    }





                                    share|improve this answer













                                    Here is my PHP version



                                    /**
                                    * Validate SSN - must be in format AAA-GG-SSSS or AAAGGSSSS
                                    *
                                    * @param $ssn
                                    * @return bool
                                    */
                                    function validate_ssn($ssn) {

                                    $ssnTrimmed = trim($ssn);

                                    // Must be in format AAA-GG-SSSS or AAAGGSSSS
                                    if ( ! preg_match("/^([0-9]{9}|[0-9]{3}-[0-9]{2}-[0-9]{4})$/", $ssnTrimmed)) {
                                    return false;
                                    }

                                    // Split groups into an array
                                    $ssnFormatted = (strlen($ssnTrimmed) == 9) ? preg_replace("/^([0-9]{3})([0-9]{2})([0-9]{4})$/", "$1-$2-$3", $ssnTrimmed) : $ssnTrimmed;
                                    $ssn_array = explode('-', $ssnFormatted);

                                    // number groups must follow these rules:
                                    // * no single group can have all 0's
                                    // * first group cannot be 666, 900-999
                                    // * second group must be 01-99
                                    // * third group must be 0001-9999

                                    foreach ($ssn_array as $group) {
                                    if ($group == 0) {
                                    return false;
                                    }
                                    }

                                    if ($ssn_array[0] == 666 || $ssn_array[0] > 899) {
                                    return false;
                                    }

                                    return true;
                                    }






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Sep 17 '16 at 23:09









                                    Jesse SzypulskiJesse Szypulski

                                    93114




                                    93114






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1517026%2fhow-can-i-validate-us-social-security-number%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        Contact image not getting when fetch all contact list from iPhone by CNContact

                                        count number of partitions of a set with n elements into k subsets

                                        A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks