Skip to content

Instantly share code, notes, and snippets.

@iL53n
Last active January 31, 2023 14:22
Show Gist options
  • Save iL53n/e142fa688eec24aebe0ca73e14a59b04 to your computer and use it in GitHub Desktop.
Save iL53n/e142fa688eec24aebe0ca73e14a59b04 to your computer and use it in GitHub Desktop.
Popup with IBAN validation input
$(function() {
$(".popup").hide();
$(document).ready(function() {
$(".popup").fadeIn(500);
});
$(".reject").click(function() {
$(".popup").fadeOut(500);
});
$(".iban-input").on("input", function() {
let val = this.value.replace(/\s/g, "");
let valChars = val.split("");
val = "";
let count = 0;
for (let i in valChars) {
if (count < 2) {
valChars[i] = valChars[i].toUpperCase();
if (!/^[A-Z]+$/.test(valChars[i])) {
break;
}
} else if (!/^[0-9]+$/.test(valChars[i])) {
continue;
}
val += valChars[i];
if ((count + 1) % 4 === 0) {
val += " ";
} else if (count + 1 === 22) {
break;
}
count++;
}
this.value = val.trim();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment