Question

In: Computer Science

create a program that does a similar thing, but checks for authentic Social Security numbers. Here...

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

Solutions

Expert Solution

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

******************************************************************************************


Related Solutions

Python Programming: Write a RegEx that validates social security numbers
Python Programming: Write a RegEx that validates social security numbers
Answer the following questions regarding Social Security. Define Social Security. How exactly does paying into Social...
Answer the following questions regarding Social Security. Define Social Security. How exactly does paying into Social Security affect your retirement savings? c. Suppose you are 40 years old and plan on retiring in 25 years, and then living for another 15 years after retirement.  Your current income is $70,000 per year.  If you pay $3,000 in Social Security taxes each year, how much do you need to save per year in order to have enough to replace 75% of your preretirement income...
Write a program that checks if all the input numbers cover 1 to 99. Each ticket...
Write a program that checks if all the input numbers cover 1 to 99. Each ticket for the Pick-10 lotto has 10 unique numbers ranging from 1 to 99. Suppose you buy a lot of tickets and like to have them cover all numbers from 1 to 99. Write a program that reads the ticket numbers from a file and checks whether all numbers are covered. Assume the last ending number in the file is 0. Suppose the file contains...
According to a survey, 47% of adults are concerned that Social Security numbers are used for...
According to a survey, 47% of adults are concerned that Social Security numbers are used for general identification. For a group of eight adults selected at random, we used Minitab to generate the binomial probability distribution and the cumulative binomial probability distribution (menu selections right-pointing arrowhead Calc right-pointing arrowhead Probability Distributions right-pointing arrowhead Binomial). Number r 0 1 2 3 4 5 6 7 8 P(r) 0.006226 0.044169 0.137091 0.243143 0.269521 0.191208 0.084781 0.021481 0.002381 P(<=r) 0.00623 0.05040 0.18749 0.43063...
C++ Create a program that checks whether a number is a prime number and displays its...
C++ Create a program that checks whether a number is a prime number and displays its factors if it is not a prime number. Console Prime Number Checker Please enter an integer between 1 and 5000: 5 5 is a prime number. Try again? (y/n): y Please enter an integer between 1 and 5000: 6 6 is NOT a prime number. It has 4 factors: 1 2 3 6 Try again? (y/n): y Please enter an integer between 1 and...
Social Security system is a pay as you go retirement plan. Money taken from workers checks...
Social Security system is a pay as you go retirement plan. Money taken from workers checks is transferred to retirees. At one time there were 42 workers per retiree; today the ratio is now under 3 to 1. By 2030, the ratio is expected to fall to 2 to 1. The only way to keep the current system solvent is to raise taxes on those currently working or cut benefits to those already retired. Neither of these options is particularly...
What is the calculation of benefits from the u.s social security program?
What is the calculation of benefits from the u.s social security program?
Unknown to you, your grandmother started depositing $25 (out of her social security checks) each month,...
Unknown to you, your grandmother started depositing $25 (out of her social security checks) each month, beginning the day you were born. Your grandmother died on your twentieth birthday, but left you the passbook. You found out that the bank maintained monthly compounding for all 20 years, but the interest rate had changed as follows: (a) Date of your birth to fifth birthday = 0.04; (b) Beginning fifth birthday to fifteenth birthday = 0.08; (c) Beginning fifteenth birthday to present...
I'm making a python program that checks the users input. If the users input does not...
I'm making a python program that checks the users input. If the users input does not match the rules then the program will output "No". If the users input does match the rules it will output "Yes". The rules are : at least 5 uppercase letters at least 5 lowercase letters at least 5 numbers No more than 20 characters in total I have managed to meet these conditions in individual python files but not in one. Ideally without importing...
I'm making a python program that checks the users input. If the users input does not...
I'm making a python program that checks the users input. If the users input does not match the rules then the program will output "No". If the users input does match the rules it will output "Yes". The rules are : 5 uppercase letters 5 lowercase letters 5 numbers First letter must be capitilized The total characters must be 15 I have managed to meet these conditions in individual python files but not in one. Ideally without importing anything, still...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT