IsValidCodeMelli

 public static bool IsValidCodeMelli(this string codeMelli)
        {
            Int64 number;
            int sum = 0, temp;
            Int64.TryParse(codeMelli, out number);
            if (Math.Log10(number) > 6 && Math.Log10(number) < 10)
            {
                temp = Convert.ToInt16(number % 10);
                number /= 10;
                for (int i = 2; i < 11; i++)
                {
                    sum += Convert.ToInt16(i * (number % 10));
                    number /= 10;
                }
                if (((sum % 11 < 2) && (sum % 11 == temp)) || ((sum % 11 >= 2) && ((11 - sum % 11) == temp)))
                    return true;
            }
            return false;
        }
Example:
string codeMelli = "4990003519";
bool isValid = codeMelli.IsValidCodeMelli();

Description

صحت کد ملی

Details

Double click on the code to select all.

 

;