In: Computer Science
Python Programming:
Write a RegEx that validates social security numbers
There a very simple module in python that can match given input with a regex pattern.
For a Social Security Number to be valid, it must satisfy the following constraints:
import re
data = input("Enter your social security number")
print(data)
pattern = "^(?!666|000|9\\d{2})\\d{3}-(?!00)\\d{2}-(?!0{4})\\d{4}$"
if (re.match(pattern,data)):
print("The SSN is valid")
else:
print("The SSN is invalid")