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:
- 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–4.8 & .NET Core 1.0–3.0)” as your application, turn off free-spacing, and turn off mode modifiers. Click the Generate button, and you’ll get this regular expression:
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: