jquery.inputmask.phone.extensions.js 2.8 KB

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