jquery.inputmask.phone.extensions.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 (factory) {
  17. if (typeof define === 'function' && define.amd) {
  18. define(['jquery', './jquery.inputmask'], factory);
  19. } else {
  20. factory(jQuery);
  21. }
  22. }(function ($) {
  23. $.extend($.inputmask.defaults.aliases, {
  24. 'phone': {
  25. url: "phone-codes/phone-codes.js",
  26. mask: function (opts) {
  27. opts.definitions = {
  28. 'p': {
  29. validator: function () { return false; },
  30. cardinality: 1
  31. },
  32. '#': {
  33. validator: "[0-9]",
  34. cardinality: 1
  35. }
  36. };
  37. var maskList = [];
  38. $.ajax({
  39. url: opts.url,
  40. async: false,
  41. dataType: 'json',
  42. success: function (response) {
  43. maskList = response;
  44. }
  45. });
  46. maskList.splice(0, 0, "+pp(pp)pppppppp");
  47. return maskList;
  48. },
  49. nojumps: true,
  50. nojumpsThreshold: 1
  51. },
  52. 'phonebe': {
  53. url: "phone-codes/phone-be.js",
  54. mask: function (opts) {
  55. opts.definitions = {
  56. 'p': {
  57. validator: function () { return false; },
  58. cardinality: 1
  59. },
  60. '#': {
  61. validator: "[0-9]",
  62. cardinality: 1
  63. }
  64. };
  65. var maskList = [];
  66. $.ajax({
  67. url: opts.url,
  68. async: false,
  69. dataType: 'json',
  70. success: function (response) {
  71. maskList = response;
  72. }
  73. });
  74. maskList.splice(0, 0, "+32(pp)pppppppp");
  75. return maskList;
  76. },
  77. nojumps: true,
  78. nojumpsThreshold: 4
  79. }
  80. });
  81. return $.fn.inputmask;
  82. }));