You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.7 KiB

  1. const ibanDemo = function() {
  2. function couldBeIBAN(str) {
  3. return str && countries.isValidISOCode(str.substring(0,2));
  4. }
  5. return {
  6. couldBeIBAN: couldBeIBAN,
  7. couldBeBBAN: function couldBeBBAN(str) {
  8. return str && !couldBeIBAN(str);
  9. }
  10. }
  11. }();
  12. $(document).ready(function(){
  13. function onIBAN(str) {
  14. let html;
  15. if (IBAN.isValid(str)) {
  16. const bban = IBAN.toBBAN(str, ' ');
  17. html = '<h3>This IBAN is VALID! <small>BBAN is ' + bban + '</small></h3>';
  18. } else {
  19. html = '<h3>This IBAN is INVALID!';
  20. }
  21. $('#results').html(html);
  22. $('#results').show();
  23. }
  24. function onBBAN(str) {
  25. let html;
  26. const country = $('#country').val();
  27. if (IBAN.isValidBBAN(country, str)) {
  28. const iban = IBAN.fromBBAN(country, str);
  29. html = '<h3>This BBAN is VALID! <small>IBAN is ' + iban + '</small></h3>';
  30. } else {
  31. html = '<h3>This BBAN is INVALID!';
  32. }
  33. $('#results').html(html);
  34. $('#results').show();
  35. }
  36. $('#userInput').bind('keyup', onChange);
  37. $('#userInput').bind('change', onChange);
  38. $('#results').hide();
  39. $('#country').hide();
  40. $('#countryLb').hide();
  41. $('#userInput').focus();
  42. function onChange() {
  43. const val = $('#userInput').val();
  44. if (ibanDemo.couldBeIBAN(val)) {
  45. $('#country').hide();
  46. $('#countryLb').hide();
  47. }
  48. if (ibanDemo.couldBeBBAN(val)) {
  49. $('#country').show();
  50. $('#countryLb').show();
  51. }
  52. }
  53. $('#goBtn').click(function() {
  54. $('#results').hide();
  55. const val = $('#userInput').val();
  56. if (ibanDemo.couldBeIBAN(val)) {
  57. onIBAN(val);
  58. }
  59. if (ibanDemo.couldBeBBAN(val)) {
  60. onBBAN(val);
  61. }
  62. });
  63. });