In: Computer Science
create a program that does a similar thing, but checks for authentic Social Security numbers. Here are two links that can help with the details. Social Security website and Social Security History website. I have to create The String with Java
import java.util.regex.*;
public class SSNvalidator {
public static boolean isValidSSN(String str)
{
// Regex to check SSN (Social Security Number).
String regex = "^(?!666|000|9\\d{2})\\d{3}-(?!00)\\d{2}-(?!0{4})\\d{4}$";
Pattern p = Pattern.compile(regex);
if (str == null) {
return false;
}
Matcher m = p.matcher(str);
return m.matches();
}
public static void main(String args[])
{
// Test Case 1:
String str1 = "856-45-6789";
System.out.println(isValidSSN(str1));
// Test Case 2:
String str2 = "000-45-6789";
System.out.println(isValidSSN(str2));
// Test Case 3:
String str3 = "856-452-6789";
System.out.println(isValidSSN(str3));
// Test Case 4:
String str4 = "856-45-0000";
System.out.println(isValidSSN(str4));
}
}
******************************************************************************************
PLEASE LIKE IT RAISE YOUR THUMBS UP
IF YOU ARE HAVING ANY DOUBT FEEL FREE TO ASK IN COMMENT
SECTION
******************************************************************************************