Check the validity of an israeli ID in .NET

Here is a simple Israeli ID validation utility.



class Program
{
    static void Main(string[] args)
    {
         string m_PERID = "111111118";
         char[] digits = m_PERID.PadLeft(9, '0').ToCharArray();
         int[] oneTwo = { 1, 2, 1, 2, 1, 2, 1, 2, 1 };
         int[] multiply = new int[9];
         int[] oneDigit = new int[9];
         for (int i = 0; i < 9; i++)
              multiply[i] = Convert.ToInt32(digits[i].ToString()) * oneTwo[i];
         for (int i = 0; i < 9; i++)
              oneDigit[i] = (int)(multiply[i] / 10) + multiply[i] % 10;
         int sum = 0;
         for (int i = 0; i < 9; i++)
              sum += oneDigit[i];
         if (sum % 10 == 0)
              Console.WriteLine("OK");
         else
              Console.WriteLine("NOT OK");

      }
}

2 Comments

Previous Post Next Post