Ejemplo n.º 1
0
        public static bool Validate(string identityNumber)
        {
            identityNumber = identityNumber.Trim();
            if (identityNumber.IsNumeric())
            {
                return(identityNumber.Length == 13 &&
                       SouthAfricanIdentityNumber.GetIdentityNumberControlDigit(identityNumber).ToString().Equals(identityNumber.Substring(12, 1)));
            }

            return(false);
        }
Ejemplo n.º 2
0
        public static string Generate()
        {
            var rand = new Random();

            while (true)
            {
                var dd = (int)Math.Floor(rand.NextDouble() * 31) + 1;
                var mm = (int)Math.Floor(rand.NextDouble() * 12) + 1;
                var yy = (int)(92 - Math.Floor(rand.NextDouble() * 50));
                var g  = (int)Math.Floor(rand.NextDouble() * 9999);

                if (dd >= 29)
                {
                    if (mm == 2)
                    {
                        dd = 28;
                    }
                    else if (dd == 31 &&
                             mm % 2 == 1)
                    {
                        dd = 30;
                    }
                }

                for (var i = 80; i < 90; i++)
                {
                    var gen = SouthAfricanIdentityNumber.Space(yy.ToString(), 2) + SouthAfricanIdentityNumber.Space(mm.ToString(), 2) + SouthAfricanIdentityNumber.Space(dd.ToString(), 2)
                              + SouthAfricanIdentityNumber.Space(g.ToString(), 2) + SouthAfricanIdentityNumber.Space(i.ToString(), 3);

                    if (SouthAfricanIdentityNumber.IsValid(gen))
                    {
                        return(gen);
                    }
                }
            }
        }