mirror of
https://github.com/skidoodle/taj-validator.git
synced 2025-03-05 20:00:40 +01:00
ASd
This commit is contained in:
parent
94026331b5
commit
820c44d377
3 changed files with 26 additions and 29 deletions
|
@ -12,11 +12,11 @@
|
|||
|
||||
<form>
|
||||
<input
|
||||
type="number"
|
||||
type="text"
|
||||
id="taj"
|
||||
oninput="restrictInput(this, 'number')"
|
||||
maxlength="9"
|
||||
required
|
||||
pattern="/^-?\d+\.?\d*$/"
|
||||
onKeyPress="if(this.value.length==9) return false;"
|
||||
/>
|
||||
<button type="button" onclick="checkTAJ()">Ellenőrzés</button>
|
||||
</form>
|
||||
|
|
43
script.js
43
script.js
|
@ -1,31 +1,28 @@
|
|||
function validateTAJ(taj) {
|
||||
taj = taj.replace(/[^0-9]/g, '');
|
||||
// Input 0
|
||||
function restrictInput(input) {
|
||||
input.value = input.value.replace(/[^0-9]/g, '').slice(0, 9);
|
||||
}
|
||||
|
||||
if (taj.length != 9) {
|
||||
return false;
|
||||
function validateTAJ(a) {
|
||||
a = a.replace(/[^0-9]/g, '');
|
||||
if (9 != a.length) {
|
||||
return !1;
|
||||
}
|
||||
|
||||
let sum = 0;
|
||||
let num = '';
|
||||
|
||||
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];
|
||||
for (var b = 0, d = '', c = 0; c < a.length; c++) {
|
||||
7 >= c &&
|
||||
((b += 0 == (c + 1) % 2 ? 7 * parseInt(a[c]) : 3 * parseInt(a[c])),
|
||||
(d += a[c]));
|
||||
}
|
||||
}
|
||||
|
||||
num += sum % 10;
|
||||
return taj == num;
|
||||
return a == d + (b % 10);
|
||||
}
|
||||
|
||||
function checkTAJ() {
|
||||
const tajInput = document.querySelector('#taj');
|
||||
const resultElement = document.querySelector('#result');
|
||||
var a = document.querySelector('#taj'),
|
||||
b = document.querySelector('#result');
|
||||
|
||||
validateTAJ(tajInput.value)
|
||||
? ((resultElement.textContent = 'A TAJ szám érvényes.'),
|
||||
(resultElement.style.color = '#4CAF50'))
|
||||
: ((resultElement.textContent = 'A TAJ szám érvénytelen.'),
|
||||
(resultElement.style.color = '#FF5733'));
|
||||
validateTAJ(a.value)
|
||||
? ((b.textContent = 'A TAJ sz\u00e1m \u00e9rv\u00e9nyes.'),
|
||||
(b.style.color = '#4CAF50'))
|
||||
: ((b.textContent = 'A TAJ sz\u00e1m \u00e9rv\u00e9nytelen.'),
|
||||
(b.style.color = '#FF5733'));
|
||||
}
|
||||
|
|
|
@ -3,18 +3,18 @@ body {
|
|||
background-color: #121212;
|
||||
color: #338ef7;
|
||||
text-align: center;
|
||||
margin-top: 10%;
|
||||
font-size: 1.5rem;
|
||||
margin: 10% auto;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
form {
|
||||
width: 300px;
|
||||
max-width: 300px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
label,
|
||||
input {
|
||||
display: block;
|
||||
margin: 10px 0;
|
||||
color: #338ef7;
|
||||
font-size: 2rem;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue