Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
ECMAScript (JavaScript)

/
(?!(\d){3}(-| |)\1{2}\2\1{4})(?!666|000|9\d{2})(\b\d{3}(-| |)(?!00)\d{2}\4(?!0{4})\d{4}\b)
/
gm

Description

This regex targets a customer specific requirement for a regex that matches US Social security numbers either separated by -(dash), space or nothing.

So it should match: 702-02-9921 702 02 9921 702029921

As it may be dangerous to have a regex that matches a sequence of 9 number I made it very strict to reduce the amount of false positives

So it should not match: Telephones, credit cards, same number sequences, 0 sequences, numbers starting with 9, mixed space and dashes

Inspired by: https://www.codeproject.com/Articles/651609/Validating-Social-Security-Numbers-through-Regular

Submitted by @rafalages - 7 years ago