jquery.inputmask.phone.extensions.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Input Mask plugin extensions
  3. http://github.com/RobinHerbots/jquery.inputmask
  4. Copyright (c) 2010 - 2014 Robin Herbots
  5. Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
  6. Version: 0.0.0
  7. Phone extension.
  8. When using this extension make sure you specify the correct url to get the masks
  9. $(selector).inputmask("phone", {
  10. url: "Scripts/jquery.inputmask/phone-codes/phone-codes.json",
  11. onKeyValidation: function () { //show some metadata in the console
  12. console.log($(this).inputmask("getmetadata")["name_en"]);
  13. }
  14. });
  15. */
  16. (function ($) {
  17. $.extend($.inputmask.defaults.aliases, {
  18. 'phone': {
  19. url: "phone-codes/phone-codes.json",
  20. mask: function (opts) {
  21. opts.definitions = {
  22. 'p': {
  23. validator: function () { return false; },
  24. cardinality: 1
  25. },
  26. '#': {
  27. validator: "[0-9]",
  28. cardinality: 1
  29. }
  30. };
  31. var maskList = [];
  32. $.ajax({
  33. url: opts.url,
  34. async: false,
  35. dataType: 'json',
  36. success: function (response) {
  37. maskList = response;
  38. }
  39. });
  40. maskList.splice(0, 0, "+p(ppp)ppp-pppp");
  41. return maskList;
  42. },
  43. nojumps: true,
  44. nojumpsThreshold: 1
  45. },
  46. 'phonebe': {
  47. url: "phone-codes/phone-be.json",
  48. mask: function (opts) {
  49. opts.definitions = {
  50. 'p': {
  51. validator: function () { return false; },
  52. cardinality: 1
  53. },
  54. '#': {
  55. validator: "[0-9]",
  56. cardinality: 1
  57. }
  58. };
  59. var maskList = [];
  60. $.ajax({
  61. url: opts.url,
  62. async: false,
  63. dataType: 'json',
  64. success: function (response) {
  65. maskList = response;
  66. }
  67. });
  68. maskList.splice(0, 0, "+32(ppp)ppp-pppp");
  69. return maskList;
  70. },
  71. nojumps: true,
  72. nojumpsThreshold: 4
  73. }
  74. });
  75. })(jQuery);