jquery.inputmask.phone.extensions.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. nojumpsThreshold: 1
  44. },
  45. 'phonebe': {
  46. url: "phone-codes/phone-be.json",
  47. mask: function (opts) {
  48. opts.definitions = {
  49. 'p': {
  50. validator: function () { return false; },
  51. cardinality: 1
  52. },
  53. '#': {
  54. validator: "[0-9]",
  55. cardinality: 1
  56. }
  57. };
  58. var maskList = [];
  59. $.ajax({
  60. url: opts.url,
  61. async: false,
  62. dataType: 'json',
  63. success: function (response) {
  64. maskList = response;
  65. }
  66. });
  67. maskList.splice(0, 0, "+32(ppp)ppp-pppp");
  68. return maskList;
  69. },
  70. nojumpsThreshold: 4
  71. }
  72. });
  73. })(jQuery);