-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
73 lines (70 loc) · 2.46 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<html>
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<title></title>
<style>
.input {
display: flex;
align-items: center;
}
input {
width: 100%;
font: inherit;
padding: 0.25em 0.5em;
border: 0.125em solid hsl(30, 76%, 10%);
outline: none;
}
</style>
</head>
<body>
<h1>Sprawdzanie poprawności numeru PESEL</h1>
Wprowadź PESEL: <input type="text" id="pesel" name="pesel" maxlength="11" required placeholder="Wpisz PESEL"><br>
<button onclick="funkcja()">Sprawdź</button><br><br><br>
Żółte tło - zbyt krótki pesel<br>
Czerwona obramówka - zły numer kontrolny<br>
Zielona obramówka - prawidłowy numer pesel<br>
</body>
<script>
var zbyt_krotkie, zly_nr;
function sprawdzPESEL(pesel) {
var reg = /^[0-9]{11}$/;
if(reg.test(pesel) == false)
return false;
else
{
var digits = (""+pesel).split("");
// if ((parseInt(pesel.substring( 4, 6)) > 31)||(parseInt(pesel.substring( 2, 4)) > 12))
// return false;
var checksum = (1*parseInt(digits[0]) + 3*parseInt(digits[1]) + 7*parseInt(digits[2]) + 9*parseInt(digits[3]) + 1*parseInt(digits[4]) + 3*parseInt(digits[5]) + 7*parseInt(digits[6]) + 9*parseInt(digits[7]) + 1*parseInt(digits[8]) + 3*parseInt(digits[9]))%10;
if(checksum==0) checksum = 10;
checksum = 10 - checksum;
return (parseInt(digits[10])==checksum);
}
}
function funkcja(){
var nr_pesel = document.getElementById('pesel').value;
if (nr_pesel.length < 11){
zbyt_krotkie = true;
} else {
zbyt_krotkie = false;
}
if(zbyt_krotkie){
document.getElementById('pesel').style.backgroundColor = 'yellow';
}
if(!zbyt_krotkie){
document.getElementById('pesel').style.backgroundColor = 'white';
}
if(sprawdzPESEL($("#pesel").val())){
document.getElementById('pesel').style.borderColor = 'green';
console.log('true');
setTimeout(function(){
window.open("http://localhost/kpesel/insert.php?pesel=" + $("#pesel").val());
}, 1000);
} else {
document.getElementById('pesel').style.borderColor = 'red';
console.log('false');
}
}
</script>
</html>