Esempio n. 1
0
        public static bool IsValid(string pesel)
        {
            var regex = new System.Text.RegularExpressions.Regex("^\\d{11}$");

            if (!regex.IsMatch(pesel))
            {
                return(false);
            }

            int checkSum  = PeselCheckSumCalculator.Calculate(pesel);
            int lastDigit = pesel.Last() - '0';

            return(lastDigit == checkSum);
        }
Esempio n. 2
0
        public string Generate(bool isMan)
        {
            var peselStringBuilder = new StringBuilder();

            do
            {
                DateTime birthDate = GenerateDate(1900, 2099);

                AppendPeselDate(birthDate, peselStringBuilder);

                peselStringBuilder.Append(GenerateRandomNumbers(3));
                if (isMan)
                {
                    peselStringBuilder.Append(ManNumber());
                }
                else
                {
                    peselStringBuilder.Append(WomanNumber());
                }
                peselStringBuilder.Append(PeselCheckSumCalculator.Calculate(peselStringBuilder.ToString()));
            } while (generatedPesels.Contains(peselStringBuilder.ToString()));
            generatedPesels.Add(peselStringBuilder.ToString());
            return(peselStringBuilder.ToString());
        }