only validate if input fields non-empty
This commit is contained in:
parent
23858eca32
commit
4e6b8ec6f0
2 changed files with 16 additions and 21 deletions
|
|
@ -129,7 +129,7 @@
|
|||
<footer class="footer">
|
||||
<div class="content has-text-centered">
|
||||
<p>
|
||||
<strong>BezahlBrudi v1.0.4</strong> by <a href="https://xengi.de">XenGi</a>.
|
||||
<strong>BezahlBrudi v1.0.5</strong> by <a href="https://xengi.de">XenGi</a>.
|
||||
The source code is licensed <a href="https://opensource.org/license/mit">MIT</a>. Find the source code on <a href="https://gitlab.com/xengi/bezahlbrudi/">GitLab</a>.
|
||||
<br/>
|
||||
This site doesn't store any data outside your browser. This site doesn't provide any financial services. It is a simple QR code generator.
|
||||
|
|
|
|||
15
js/index.js
15
js/index.js
|
|
@ -30,6 +30,7 @@ setCookie = () => {
|
|||
// Field data checks
|
||||
|
||||
validateName = (target) => {
|
||||
if (target.value.length == 0) return
|
||||
if (target.value.length > 0 && target.value.length <= 70) {
|
||||
target.classList.remove("is-danger")
|
||||
document.querySelector("#name div span").innerHTML = "✅";
|
||||
|
|
@ -50,6 +51,7 @@ validateName = (target) => {
|
|||
}
|
||||
|
||||
validateBic = (target) => {
|
||||
if (target.value.length == 0) return
|
||||
const re = /^[a-z]{6}[2-9a-z][0-9a-np-z]([a-z0-9]{3}|x{3})?$/i;
|
||||
|
||||
if (re.test(target.value)) {
|
||||
|
|
@ -72,6 +74,7 @@ validateBic = (target) => {
|
|||
}
|
||||
|
||||
validateIban = (target) => {
|
||||
if (target.value.length == 0) return
|
||||
// IBANs are fucking complicated. this is a hugely simplified check
|
||||
const re = /^[a-z]{2}[0-9]{20}$/i;
|
||||
|
||||
|
|
@ -95,6 +98,7 @@ validateIban = (target) => {
|
|||
}
|
||||
|
||||
validateAmount = (target) => {
|
||||
if (target.value == 0) return
|
||||
if (parseFloat(target.value) > 0 && target.value.toString() === parseFloat(target.value).toFixed(2).toString()) {
|
||||
target.value = parseFloat(target.value).toFixed(2);
|
||||
target.classList.remove("is-danger")
|
||||
|
|
@ -106,6 +110,7 @@ validateAmount = (target) => {
|
|||
}
|
||||
|
||||
validatePurpose = (target) => {
|
||||
if (target.value.length == 0) return
|
||||
const re = /[a-zA-Z0-9\/?:().,'+\- ]{1,140}/i;
|
||||
|
||||
if (re.test(target.value)) {
|
||||
|
|
@ -128,38 +133,28 @@ validatePurpose = (target) => {
|
|||
}
|
||||
|
||||
document.querySelector("#name input").addEventListener("input", (event) => {
|
||||
if (event.target.value.length > 0) {
|
||||
validateName(event.target);
|
||||
regenerate();
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelector("#iban input").addEventListener("input", (event) => {
|
||||
if (event.target.value.length > 0) {
|
||||
validateIban(event.target);
|
||||
regenerate();
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelector("#bic input").addEventListener("input", (event) => {
|
||||
if (event.target.value.length > 0) {
|
||||
validateBic(event.target);
|
||||
regenerate();
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelector("#amount input").addEventListener("input", (event) => {
|
||||
if (event.target.value.length > 0) {
|
||||
validateAmount(event.target);
|
||||
regenerate();
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelector("#purpose input").addEventListener("input", (event) => {
|
||||
if (event.target.value.length > 0) {
|
||||
validatePurpose(event.target);
|
||||
regenerate();
|
||||
}
|
||||
});
|
||||
|
||||
// Remember inputs
|
||||
|
|
|
|||
Loading…
Reference in a new issue