我如何可以验证美国社会安全号码? [英] How can I validate US Social Security Number?

查看:341
本文介绍了我如何可以验证美国社会安全号码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人在那里知道如何改进这个功能呢?我并不担心缩短code,我敢肯定,这能更好的正则表达式来完成,我更关心的是正确的逻辑。我有一个可怕的时间寻找文档SSN#的。大部分时间我用下面的规则都来自谁在信贷行业工作,其他的程序员(没有引用来源)。

  1. 是否有任何其他规则 你知道吗?
  2. 请您知道任何这是错的?
  3. 你能现场的来源是什么?

感谢您的见解!

 公共静态布尔isSSN(字符串SSN)
    {
        正则表达式rxBadSSN =新的正则表达式(@(\ d)\ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1 \ 1);

        //必须是9个字节
        如果(ssn.Trim()。长度!= 9)
            返回false;

        //必须是数字
        如果(!ISNUMERIC(SSN))
            返回false;

        //必须小于772999999
        如果((Int32)已Double.Parse(ssn.Substring(0,3))> 772)
        {
            //检查绿卡温度SSN持有人
            //可能是900700000
            // 900800000
            如果(ssn.Substring(0,1)!=9)
                返回false;

            如果(ssn.Substring(3,1)=7&安培;!&安培;!ssn.Substring(3,1)=8)
                返回false;
        }

        //显然是假的!
        如果(SSN ==123456789)
            返回false;

        //再试一次!
        如果(SSN ==123121234)
            返回false;

        //没有一个单一的组可以有全部为零
        如果(ssn.Substring(0,3)==000)
            返回false;
        如果(ssn.Substring(3,2)==00)
            返回false;
        如果(ssn.Substring(5,4)==0000)
            返回false;

        //检查以确保SSN数量不重复
        如果(rxBadSSN.IsMatch(SSN))
            返回false;

        返回true;
    }
 

解决方案

更新

6月25日,2011年,SSA改变了SSN分配过程为SSN随机化[27] ​​SSN随机影响SSN分配过程在以下几个方面:

有消除了SSN,previously称为区域号码,通过不再分配区号码的分配,以在特定状态的个体的前三位的地理意义。 它消除的最高组号码的意义,并且作为结果,高组列表被冻结在时间和可用于随机化实施日期之前发放的SSN的验证。 previously未分配的区域号码目前已经提出了分配不包括区号000,666和900-999。

新规则

  • 在社会安全号码的格式为AAA-GG-SSSS九位数字。的数量被分成三个部分。
  • 在中间的两个数字是组号。组号范围从01到99。
  • 最后四位数字是序列号。他们重新present从0001位直数值列9999组内。
  • 在一些特殊的号码从未分配:
    • 数字以任何数字组中的所有零(000 - ## - ####,### - 00 - ####,### - ## - 0000)。
    • 第一个数字组中的
    • 在数字与666或900-999(个人纳税识别号码)。
  • 核潜艇<一href="http://en.wikipedia.org/wiki/Social_Security_number#SSNs_invalidated_by_use_in_advertising">used广告已经呈现这些数字无效。

<一个href="http://en.wikipedia.org/wiki/Social_Security_number#Structure">http://en.wikipedia.org/wiki/Social_Security_number#Structure

previous答案

下面是一个SSN的妆最完整的描述我发现。

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)\1\1\1\1\1\1\1\1");

        //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;
    }

解决方案

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.

这篇关于我如何可以验证美国社会安全号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆