Last active
January 31, 2023 14:22
-
-
Save iL53n/e142fa688eec24aebe0ca73e14a59b04 to your computer and use it in GitHub Desktop.
Popup with IBAN validation input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(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