This commit is contained in:
skidoodle 2023-10-26 19:37:31 +02:00
parent 94026331b5
commit 820c44d377
3 changed files with 26 additions and 29 deletions

View file

@ -12,11 +12,11 @@
<form> <form>
<input <input
type="number" type="text"
id="taj" id="taj"
oninput="restrictInput(this, 'number')"
maxlength="9"
required required
pattern="/^-?\d+\.?\d*$/"
onKeyPress="if(this.value.length==9) return false;"
/> />
<button type="button" onclick="checkTAJ()">Ellenőrzés</button> <button type="button" onclick="checkTAJ()">Ellenőrzés</button>
</form> </form>

View file

@ -1,31 +1,28 @@
function validateTAJ(taj) { // Input 0
taj = taj.replace(/[^0-9]/g, ''); function restrictInput(input) {
input.value = input.value.replace(/[^0-9]/g, '').slice(0, 9);
}
if (taj.length != 9) { function validateTAJ(a) {
return false; a = a.replace(/[^0-9]/g, '');
if (9 != a.length) {
return !1;
} }
for (var b = 0, d = '', c = 0; c < a.length; c++) {
let sum = 0; 7 >= c &&
let num = ''; ((b += 0 == (c + 1) % 2 ? 7 * parseInt(a[c]) : 3 * parseInt(a[c])),
(d += a[c]));
for (let i = 0; i < taj.length; i++) {
if (i <= 7) {
sum += (i + 1) % 2 == 0 ? parseInt(taj[i]) * 7 : parseInt(taj[i]) * 3;
num += taj[i];
} }
} return a == d + (b % 10);
num += sum % 10;
return taj == num;
} }
function checkTAJ() { function checkTAJ() {
const tajInput = document.querySelector('#taj'); var a = document.querySelector('#taj'),
const resultElement = document.querySelector('#result'); b = document.querySelector('#result');
validateTAJ(tajInput.value) validateTAJ(a.value)
? ((resultElement.textContent = 'A TAJ szám érvényes.'), ? ((b.textContent = 'A TAJ sz\u00e1m \u00e9rv\u00e9nyes.'),
(resultElement.style.color = '#4CAF50')) (b.style.color = '#4CAF50'))
: ((resultElement.textContent = 'A TAJ szám érvénytelen.'), : ((b.textContent = 'A TAJ sz\u00e1m \u00e9rv\u00e9nytelen.'),
(resultElement.style.color = '#FF5733')); (b.style.color = '#FF5733'));
} }

View file

@ -3,18 +3,18 @@ body {
background-color: #121212; background-color: #121212;
color: #338ef7; color: #338ef7;
text-align: center; text-align: center;
margin-top: 10%;
font-size: 1.5rem; font-size: 1.5rem;
margin: 10% auto;
width: 100%;
} }
form { form {
width: 300px; max-width: 300px;
margin: 0 auto; margin: 0 auto;
} }
label, label,
input { input {
display: block;
margin: 10px 0; margin: 10px 0;
color: #338ef7; color: #338ef7;
font-size: 2rem; font-size: 2rem;