Checks whether a text value matches a basic US SSN format
=LET(
s, REGEXREPLACE(TRIM(ssn), "[^0-9]", ""),
AND(
LEN(s)=9,
NOT(REGEXMATCH(s, "^(000|666|9\d\d)")),
NOT(REGEXMATCH(s, "^\d{3}000")),
NOT(REGEXMATCH(s, "^\d{5}0000"))
)
)This function performs a simple validation check to see whether a text value looks like a valid US Social Security Number (SSN). This function does not verify that an SSN is real or assigned to a specific person, it only checks whether the value matches basic SSN formatting and invalid-number rules. The function verifies the input matches either ###-##-#### or #########, rejects all-zero groups (like 000-12-3456, 123-00-4567, 123-45-0000), and rejects obviously invalid values when it contains non-digits. For example, if A2 contains 123-45-6789, then =IS_VALID_SSN(A2) returns TRUE, while if A3 contains 000-12-3456, =IS_VALID_SSN(A3) returns FALSE.
Use the inputs below to create IS_VALID_SSN as a reusable custom function in Google Sheets.
Learn how to add custom functions to Google SheetsIS_VALID_SSN
Checks whether a text value matches a basic US SSN format
=LET( s, REGEXREPLACE(TRIM(ssn), "[^0-9]", ""), AND( LEN(s)=9, NOT(REGEXMATCH(s, "^(000|666|9\d\d)")), NOT(REGEXMATCH(s, "^\d{3}000")), NOT(REGEXMATCH(s, "^\d{5}0000")) ) )
ssn
Text string representing an SSN (with or without dashes)
A1
Other functions in the same category: Data Validation
Checks if a card number passes the Luhn (MOD 10) checksum
Checks whether a text value matches a basic email address format
Checks whether a text value is a valid IPv4 address
Checks whether a text value is a valid IPv6 address
Checks whether a text value is a valid ISBN-10
Checks whether a text value is a valid ISBN-13
Named functions enable the creation of custom, reusable formulas that mimic built-in functions, streamlining calculations and data manipulations. These functions simplify complex formulas, making spreadsheets more readable and less prone to errors. By encapsulating intricate logic within a single function call, they enhance consistency across your data. Utilizing named functions reduces the need to write lengthy formulas repeatedly, thereby improving workflow efficiency and productivity in data analysis and management.
Download and import — fastest way to add the function but does not include argument descriptions and examples
Follow these simple steps to download and import a function into your spreadsheet. This method is the quickest and easiest way to add the named function to your Google Sheets document, but will not include the argument description and examples.
Once added, the function will be ready to use in your document like any other built-in function. Simply type the function name and provide the required inputs to use it in your calculations.
Copy and paste — copy and paste each property one at a time
Follow these simple steps to integrate a custom named function into your spreadsheet:
Once added, the function will be ready to use in your document like any other built-in function. Simply type the function name and provide the required inputs to use it in your calculations.