Konuyu Oyla:
  • Toplam: 0 Oy - Ortalama: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Javascript ile TC kimlik no doğrulama algoritması
#1
Kod:
<html>

<head>
    <meta charset="utf-8" />
    <title>Sayfa Başlığı</title>
</head>

<body>
    <input type="text" id="sayi" />
    <button onclick="f()">Hesapla</button>
  <div id="sonuc" style="padding: 10px 0px;"></div>
    <script>
        function f() {
            var i;
            var sayi = parseInt(document.getElementById("sayi").value);

            var tc_no = new Array();

            for (i = 10; i > 0; i--) {
                tc_no.push(parseInt(sayi / (Math.pow(10, i)) % 10));
            }

            tc_no.push(parseInt(sayi % 10));

            var toplam1 = 0, toplam2 = 0, tumtoplam = 0;
            var sonuc = "";

            if (tc_no[0] != 0) {
                for (i = 0; i < tc_no.length - 1; i += 2) {
                    toplam1 += tc_no[i];
                }
                toplam1 *= 7;
                for (i = 1; i < tc_no.length - 2; i += 2) {
                    toplam2 += tc_no[i];
                }
                if (tc_no[9] == (toplam1 - toplam2) % 10) {
                    for (i = 0; i < tc_no.length - 1; i++) {
                        tumtoplam += tc_no[i];
                    }
                    if (tumtoplam % 10 == tc_no[10]) {
                        sonuc = "<span style='color: green'>TC kimlik no doğru.</span>";
                    } else {
                      sonuc = "<span style='color: red'>TC kimlik no doğru değil.</span>";
                    }
                } else {
                    sonuc = "<span style='color: red'>TC kimlik no doğru değil.</span>";
                }
            } else {
                sonuc = "<span style='color: red'>TC kimlik no doğru değil.</span>";
            }
            document.getElementById("sonuc").innerHTML= sonuc;
        }
    </script>
</body>

</html>

Algoritmanın mantığı zaten basit. Kodlardan çıkarabilirsiniz.

(Güncellendi // 21.11.2020)
1
Ara
Cevapla PGM
Teşekkür verenler: Novruz , blackbear


Bu Konudaki Yorumlar
Javascript ile TC kimlik no doğrulama algoritması - Yazar: Codeless - 20-12-2019 Saat: 13:04

Hızlı Menü:


Şu anda bu konuyu okuyanlar: 1 Ziyaretçi


Online Shopping App
Online Shopping - E-Commerce Platform
Online Shopping - E-Commerce Platform
Feinunze Schmuck Jewelery Online Shopping