All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.javafaker.idnumbers.EnIdNumber Maven / Gradle / Ivy

Go to download

This library is a port of Ruby's stympy/faker gem (as well as Perl's Data::Faker library) that generates fake data. It's useful when you're developing a new project and need some pretty data for showcase.

There is a newer version: 1.0.2
Show newest version
package com.github.javafaker.idnumbers;

import com.github.javafaker.Faker;

public class EnIdNumber {
    private static final String[] invalidSSNPatterns = {
            "0{3}-\\\\d{2}-\\\\d{4}",
            "\\d{3}-0{2}-\\d{4}",
            "\\d{3}-\\d{2}-0{4}",
            "666-\\d{2}-\\d{4}",
            "9\\d{2}-\\d{2}-\\d{4}"};

    public String getValidSsn(Faker f) {
        String ssn = f.regexify("[0-8]\\d{2}-\\d{2}-\\d{4}");

        boolean isValid = true;
        for (int i = 0; i < invalidSSNPatterns.length; i++) {
            if (ssn.matches(invalidSSNPatterns[i])) {
                isValid = false;
                break;
            }
        }
        if (!isValid) {
            ssn = getValidSsn(f);
        }
        return ssn;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy