Validating telephone numbers dating tips service com
This blog post focuses on validating the last of those : Social Security Numbers and why they may be a bit deceivingly more difficult to validate than you might expect.
I’ll provide a few different methods to handle the actual validation through Regular Expressions and let you determine which one might best suit your needs.
A Social Security number (SSN) is a nine-digit number issued to U. citizens, permanent residents and temporary residents under section 205(c)(2) of the Social Security Act.
The number is issued to an individual by the Social Security Administration and primary purpose is to track individuals for the U. Social Security program, which can allocate benefits and is commonly referred to as a unique identifier for individuals within the United States for a variety of federal purposes. The number itself can be broken into three major components and appears in the following format (with or without dashes) : You may notice a great deal of past-tense within the previous descriptions.
The United States is not the only country to use Social Security Numbers, but for demonstration purposes we will focus on validating U. This is because on June 25th, 2011, the Social Security Administration revised their assignment process to use a system of randomization that had the following changes : The previously mentioned "randomization act" made it significantly easier to use a mechanism such as a Regular Expression to handle validating Social Security Numbers.
Since you no longer would have to worry about the highest group number and area number that had been assigned.
However, you still can't just go throwing any values into there and expecting it to be valid as the Social Security Administration still has a few Social Security Numbers that are explicitly "off limits" as mentioned below.
A valid Social Security Number cannot : This method is about as straight-forward as possible and surprisingly it will actually validate every single possible Social Security Number out there, but the problem is that many of the values that it would accept aren't even valid values.
You can see an example of this in action below : While this may not look very fun at all, it will validate any valid Social Security Number as per the constraints (and exceptions) listed by the Social Security Administration.
Let’s break this one down to see what is going on : ^ # Start of expression (?!
2|0) # Don't allow "219-09-999" or "0" explicitly (?!
666|000|9\d)\d # Don't allow the SSN to begin with 666, 000 or anything between 900-999 - # Explicit dash (separating Area and Group numbers) (?!
00)\d # Don't allow the Group Number to be "00" - # Another dash (separating Group and Serial numbers) (?!