C# Regular expression to validate U.S. Social Security Number (SSN)
By: admin on 06/28/2011 - 7366 views

Tags: regular expression, regex, social security number, ssn, c#

Social Security Number in the United States is a nine digit number in one of the following formats.
222-22-2222
222222222

Here is the regular expression to validate a Social Security Number with or without dashes.
^\d{3}\-?\d{2}\-?\d{4}$

Here is the regular expression to validate a social security number with dashes
^\d{3}-\d{2}-\d{4}$

Here is the regular expression to validate a social security number without dashes
^(\d{9})$

Other Articles

How to send emails using GMail SMTP in ASP.NET

How to bind a GridView control to an XML data source

Creating a simple XML string using LINQ to XML

Delete all the cookies created by a website in ASP.NET

Display all the cookies created by a website in ASP.NET

Creating, reading, and deleting cookies in ASP.NET

How To: Page Level Caching in ASP.NET

HOW TO: How to insert an image or binary data into a SQL Server table using T-SQL?

Using the ValidationSummary Control in ASP.NET

Using the CustomValidator Control in ASP.NET