Pattern: National ID
“National ID” is one of the patterns that you can select on the Match panel. Use it to make a field match a personal identification code used in a specific country such as social security numbers, identity numbers, citizen numbers, tax numbers, license plate numbers, etc.
This example shows how you can use the “national ID” pattern to look for US social security numbers. You can find this example as “Pattern: national ID” in the RegexMagic library.
- Click the New Formula button on the top toolbar to clear out all settings on the Samples, Match, and Action panels.
- On the Samples panel, paste in one new sample that has a block of valid and a block of invalid US social security numbers:
Valid:
123-12-1234
078-05-1120
Invalid:
123121234
1234-12-1234
000-00-0000
- On the Match panel, click the button to add field .
- In the “pattern to match field” drop-down list, select “national ID”.
- In the “kind of ID” drop-down list, select “US social security number”.
- Set the “field validation mode” to “strict”, to make sure the “national ID” pattern generates a regex that excludes invalid social security numbers such as those beginning with 000 or 666.
- On the Regex panel, select “C# (.NET 2.0–8.0)” as your application, turn off free-spacing, and turn off mode modifiers. Click the Generate button, and you’ll get this regular expression:
\b(?!000|666)[012345678][0-9]{2}-(?!00)[0-9]{2}-(?!0000)[0-9]{4}\b
Unused options: Case sensitive; Exact spacing; Dot doesn’t match line breaks; ^$ don’t match at line breaks; Numbered capture.
- The Samples panel now highlights the valid social security numbers matched by our regular expression:
Valid:
123-12-1234
078-05-1120
Invalid:
123121234
1234-12-1234
000-00-0000
Reference